Hi Community,
I am looking to use a function to generate an html fragment (as in just the opening line of a div layer for instance) inserted into an XML template with a three parameters.
I have tried both the StringBuilder approach and the HTMLTextWriter approach to build up the output in an inline function which looks fine in the console but in C1 rendering I loose the special characters, even if the output is surrounded in CDATA.
Furthermore the HTMLTextwriter gives me trouble later as I cant seem to create an override to just create a RenderEndTag in a similar function as HTMLTextWriter is hard wired to deduce what type of closing tag it needs based on a required BeginTag (which in my fragment function I do not provide !!)
The reason for my approach here is that I do not want to embed a lot of other code and functions inside this fragment function, and looking for a way to be able to generate a single opening html fragment and later in the template add a closing function based on a few given parameters and the rest of the function using dynamic data to fill content within the fragment.
This is the Opening html tag fragment function =
Am I going about this totally wrong or am I missing something simple ?
I am looking to use a function to generate an html fragment (as in just the opening line of a div layer for instance) inserted into an XML template with a three parameters.
I have tried both the StringBuilder approach and the HTMLTextWriter approach to build up the output in an inline function which looks fine in the console but in C1 rendering I loose the special characters, even if the output is surrounded in CDATA.
Furthermore the HTMLTextwriter gives me trouble later as I cant seem to create an override to just create a RenderEndTag in a similar function as HTMLTextWriter is hard wired to deduce what type of closing tag it needs based on a required BeginTag (which in my fragment function I do not provide !!)
The reason for my approach here is that I do not want to embed a lot of other code and functions inside this fragment function, and looking for a way to be able to generate a single opening html fragment and later in the template add a closing function based on a few given parameters and the rest of the function using dynamic data to fill content within the fragment.
This is the Opening html tag fragment function =
using System.IO;
using System.Linq;
using System.Web.UI;
using Composite.Data;
namespace MyRentals.Functions
{
public static class InlineMethodFunction
{
public static StringWriter Fn_DomLayerOP(string DomType, string Class, string Title)
{
// Initialize StringWriter instance.
StringWriter stringWriter = new StringWriter();
string SiteLocation = "";
string SiteRegion = "";
string SiteVacation = "";
using (DataConnection connection = new DataConnection())
{
SiteLocation = (from d in connection.Get<ALocal.settings>()
where d.settings_variable == "SITE_LOCATION"
select d.settings_variablecontent).First().ToString();
SiteRegion = (from d in connection.Get<ALocal.settings>()
where d.settings_variable == "SITE_REGION"
select d.settings_variablecontent).First().ToString();
SiteVacation = (from d in connection.Get<ALocal.settings>()
where d.settings_variable == "LANG_VACATION"
select d.settings_variablecontent).First().ToString();
}
// Put HtmlTextWriter in using block because it needs to call Dispose.
using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
{
// XMLString.Append("<" + DomType + " class='" + Class + "' title='" + SiteLocation + " " + SiteRegion + " " + SiteVacation + " " + Title + "'>");
writer.AddAttribute(HtmlTextWriterAttribute.Class, Class);
writer.AddAttribute(HtmlTextWriterAttribute.Title, (SiteLocation + " " + SiteRegion + " " + SiteVacation + " " + Title));
writer.AddAttribute(HtmlTextWriterAttribute.Class, Class);
writer.AddAttribute(HtmlTextWriterAttribute.Title, (SiteLocation + " " + SiteRegion + " " + SiteVacation + " " + Title));
if (DomType == "div")
{
writer.RenderBeginTag(HtmlTextWriterTag.Div);
}
if (DomType == "h2")
{
writer.RenderBeginTag(HtmlTextWriterTag.H2);
}
//End tag in Fn_DomLayerCL.cs
}
// Return the result.
return stringWriter;
}
static void Main()
{
// Demonstrate HtmlTextWriter.
//Console.WriteLine(Fn_DomLayerOP());
}
}
}
and the snippet from within its relative tag closing function =using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter, string.Empty))
{
if (DomType == "div")
{
writer.RenderEndTag(HtmlTextWriterTag.Div);
}
if (DomType == "h2")
{
writer.RenderEndTag(HtmlTextWriterTag.H2);
}
}
A StringBuilder in the closing tag function outputs what I need, but again... converts the < > to "<" ">" in the XML/HTML Renderer output :(Am I going about this totally wrong or am I missing something simple ?