Dynamicweb.Rendering Namespace > Template Class > SetTag Method : SetTag(String,DateTime,String) Method |
Imports Dynamicweb.Rendering Public Class TemplateSample Public Function RenderTemplate() As String 'Load template from /Files/Templates/MyModuleName/List.html Dim t As New Template("MyModuleName/List.html") 'Render string template tag <!--@WelcomeMessage--> t.SetTag("WelcomeMessage", "Hello world") 'Render boolean template tag <!--@IsTuesDay--> t.SetTag("IsTuesday", Now.DayOfWeek = System.DayOfWeek.Tuesday) 'Render a datetime template tag <!--@TodaysDate--> - and also the <!--@TodaysDate.*--> date time extensions t.SetTag("TodaysDate", Now) 'Test if the loaded template contains a specific tag - if not do not do expensive work. If t.TagExists("MyCalculation") Then t.SetTag("MyCalculation", "CallExpensiveMethod()") End If 'Test if the loop MyItems is present in the loaded template, and if not the code will not be executed. If t.LoopExists("MyItems") Then 'Create a loop in the template <!--@LoopStart(MyItems)--><!--@LoopEnd(MyItems)--> Dim t2 As Template = t.GetLoop("MyItems") For i As Integer = 1 To 5 'Render a counter as a template tag inside the loop <!--@MyCounter--> t2.SetTag("MyCounter", i) 'Commit the loop and make ready for the next iteration t2.CommitLoop() Next End If 'Render the template html with the parsed template tags and loops. Return t.Output() End Function End Class
using System; using Dynamicweb.Rendering; namespace Dynamicweb.Examples.CSharp.Rendering { class TemplateSample { public string RenderTemplate() { //Load template from /Files/Templates/MyModuleName/List.html var t = new Template("MyModuleName/List.html"); //Render string template tag <!--@WelcomeMessage--> t.SetTag("WelcomeMessage", "Hello world"); //Render boolean template tag <!--@IsTuesDay--> t.SetTag("IsTuesday", DateTime.Now.DayOfWeek == System.DayOfWeek.Tuesday); //Render a datetime template tag <!--@TodaysDate--> - and also the <!--@TodaysDate.*--> date time extensions t.SetTag("TodaysDate", DateTime.Now); //Test if the loaded template contains a specific tag - if not do not do expensive work. if (t.TagExists("MyCalculation")) { t.SetTag("MyCalculation", "CallExpensiveMethod()"); } //Test if the loop MyItems is present in the loaded template, and if not the code will not be executed. if (t.LoopExists("MyItems")) { //Create a loop in the template <!--@LoopStart(MyItems)--><!--@LoopEnd(MyItems)--> Template t2 = t.GetLoop("MyItems"); for (var i = 1; i <= 5; i++) { //Render a counter as a template tag inside the loop <!--@MyCounter--> t2.SetTag("MyCounter", i); //Commit the loop and make ready for the next iteration t2.CommitLoop(); } } //Render the template html with the parsed template tags and loops. return t.Output(); } } }
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2