Jul
30
30
New Generic EPiServer Page Type
C, EPiServer, Generic Lincoln University, HTML, qualifications Comments Off on New Generic EPiServer Page Type
New Generic EPiServer Page Type
For you budding coders new or otherwise.
A simple piece of code which when its added to the load event of a EPiServer page can pull any variable from EPiServer or SharePoint using a HTML template with some tags embedded in it
Under development here http://webdev.lincoln.ac.nz/ Degrees-Diplomas-and- Certificates/Courses-A---Z/ Course2014/?CourseCode=QMET+ 307
EPiServer page templates in Visual Studio 2008
A bit of the HTML template. For example the tags labelled [sp:Title] with the value of a SharePoint variable called Title The same thing applies to EPI server values when a [es:TemplateFileName] tag is found its value is replaced with the EPiServer value for the page in question called TemplateFileName
Here is the EPiServer page property setup for the course2014 page type. New property variable can be added here and displayed on a page without recompiling the whole website which improves the process with much lower technical risk and more flexibility, allowing user editing of the content in SharePoint and/or EPiServer as user currently do for any page and allowing the developer to create rich web content and test it of line.
A side effect of this development will allow us to upgrade the new Quals pages so the actual content can be edited in the same way as any other EPiServer page
A bit of the template file
<link rel="stylesheet" type="text/css" href="/QualsReform2014/Styles/ coursereform2014.css" />
<script type="text/JavaScript" src="/QualsReform2014/script/ coursereform2014.js"></script>
<div style="background:red">
<div class="course_id_container">
<h1><script type="text/JavaScript">CourseI D('[sp:CourseCode]')</script> <script type="text/JavaScript">CourseD escription('[sp:Title]')</scri pt></h1>
</div>
<div id="course_info">
<div id="course_container">
<br />
<div id="course_desciption">
<script type="text/JavaScript">Introdu ction('[sp:Introduction]')</sc ript>
</div>
<br />
The C# code that loads and parses the HTML template and replaces the tags with values
try
{
string filename = TemplateFileName;
if (!File.Exists(filename))
{
template.Append("Template file not found
" + filename + "
");" + filename + "
return;
}
string courseCode = Request[StructuredSearchContro ller.CourseQueryID];
if (courseCode == null)
{
template.Append("Course code argument supplied is invalid
");
");
return;
}
if (courseCode.Length < 3)
{
template.Append("No course code argument supplied
");
");
return;
}
myStructuredRecored = DynamicStructuredDataUtility. GetCourse(courseCode);
if (myStructuredRecored == null)
{
template.Append("Invalid course code supplied
");
");
return;
}
//Grab the template and do the work
using (StreamReader sr = new StreamReader(filename))
{
while (!sr.EndOfStream)
{
string fline = sr.ReadLine();
//Handle SharePoint fields
int FSPfldi = 0;
int SSPfldi = fline.IndexOf("[sp:", FSPfldi);
while (SSPfldi > -1)
{
FSPfldi = fline.IndexOf("]", SSPfldi);
string SPfieldName = fline.Substring(SSPfldi+4, FSPfldi- SSPfldi - 4);
//template.Append(SPfieldName + "
");
");
if (!string.IsNullOrEmpty( SPfieldName))
{
"; }
");
}
if (FSPfldi > fline.Length)
break;
SSPfldi = fline.ToUpper().IndexOf("[SP:" , FSPfldi);
}//End of while (SSPfldi > -1)
//Handle EPiServer Fields
int FEPifldi = 0;
int SEPifldi = fline.IndexOf("[es:", FEPifldi);
while (SEPifldi > -1)
{
FEPifldi = fline.IndexOf("]", SEPifldi);
string EPifieldName = fline.Substring(SEPifldi + 4, FEPifldi - SEPifldi - 4);
//template.Append(EPifieldName + "
");
");
if (!string.IsNullOrEmpty( EPifieldName))
{
"; }
");
}
if (FEPifldi > fline.Length)
SEPifldi = fline.ToUpper().IndexOf("[ES:" , FEPifldi);
}//End of while (SEPifldi > -1)
//Add modified line to output
template.Append(fline);
}
}
//Response.Write(template);
}
catch (Exception ex)
{
template.Append(ex.Message);
template.Append(ex.StackTrace) ;
}