Dynamicweb 8 Documentation
SetTag(String,DateTime) Method
Example 

The name of the template tag, <--@NameOfTag-->.
The date value replacing the template tag specified in the name.
Specifies a tag value of type date with the specified culture. Adds a series of Date/Time extensions to the base template name. See http://templates.dynamicweb-cms.com/TemplateTags/Dynamicweb-template-tags/General-tags/Date/time-tag-extensions.aspx.
Syntax
'Declaration
 
Public Overloads Sub SetTag( _ 
   ByVal name As String, _ 
   ByVal value As Date _ 
) 
public void SetTag( 
   string name,
   DateTime value 
)

Parameters

name
The name of the template tag, <--@NameOfTag-->.
value
The date value replacing the template tag specified in the name.
Example
Full template exampleFull template example
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();
        }

    }
}
Requirements

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

See Also

Reference

Template Class
Template Members
Overload List

Send Feedback