Dynamicweb.Rendering Namespace > Template Class > SetTags Method : SetTags(TagCollection) Method |
'Declaration
Public Overloads Sub SetTags( _ ByVal values As TagCollection _ )
public void SetTags( TagCollection values )
Imports Dynamicweb.Rendering Public Class TagSample Public Shared Sub AddTags(ByVal t As Template) 'Create a tag instance and add it to a template instance Dim myTag As New Tag("greeting", "Hello") t.Tags.Add(myTag) 'Create a second tag instance using its Name and Value properties and add it to a template instance Dim myTag2 As New Tag() myTag2.Name = "greeting2" myTag2.Value = " World!" t.Tags.Add(myTag2) 'Create a collection of tags and add it to a template instance Dim myTags As New TagCollection For i As Integer = 1 To 5 myTags.Add(New Tag("Counter" & i.ToString(), i.ToString())) Next t.Tags.Add(myTags) 'Examine all the tags in the template instance. For Each tag As Tag In t.Tags If tag.Name = "greeting" Then 'Found the tag in the collection named "greeting" End If Next 'Or look it up If t.Tags.ContainsTagName("greeting") Then 'Found the tag in the collection named "greeting" End If 'And clear all tags from the template instances tags collection t.Tags.Clear() End Sub 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