private void _addStringToHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId, string position) { bool hasAspNetContentBeginning = false; string design = ""; string directive = ""; if (tmp != null) { try { XmlDocument templateXml = new XmlDocument(); templateXml.PreserveWhitespace = true; //Make sure that directive is remove before hacked non html4 compatiple replacement action... design = tmp.Design; splitDesignAndDirective(ref design, ref directive); //making sure that the template xml has a root node... if (tmp.MasterTemplate > 0) { templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "<root>" + design + "</root>", true)); } else { templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); } XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); if (xmlElement != null) { if (position == "beginning") { xmlElement.InnerXml = "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n" + xmlElement.InnerXml; } else { xmlElement.InnerXml = xmlElement.InnerXml + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true) + "\n"; } } tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); tmp.Save(); } catch (Exception ex) { umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, ex.ToString()); } } else { umbraco.BusinessLogic.Log.Add(umbraco.BusinessLogic.LogTypes.Debug, -1, "template not found"); } }
private void _removeStringFromHtmlElement(template.Template tmp, string value, string templateAlias, string htmlElementId) { bool hasAspNetContentBeginning = false; string design = ""; string directive = ""; if (tmp != null) { try { XmlDocument templateXml = new XmlDocument(); templateXml.PreserveWhitespace = true; //Make sure that directive is remove before hacked non html4 compatiple replacement action... design = tmp.Design; splitDesignAndDirective(ref design, ref directive); //making sure that the template xml has a root node... if (tmp.MasterTemplate > 0) { templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, "<root>" + design + "</root>", true)); } else { templateXml.LoadXml(helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, design, true)); } XmlNode xmlElement = templateXml.SelectSingleNode("//* [@id = '" + htmlElementId + "']"); if (xmlElement != null) { string repValue = helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, value, true); xmlElement.InnerXml = xmlElement.InnerXml.Replace(repValue, ""); } tmp.Design = directive + "\n" + helper.parseToValidXml(tmp, ref hasAspNetContentBeginning, templateXml.OuterXml, false); tmp.Save(); } catch (Exception ex) { LogHelper.Error <addStringToHtmlElement>("An error occurred", ex); } } else { LogHelper.Debug <addStringToHtmlElement>("template not found"); } }