Dynamicweb 8 Documentation
Output Method (Template)
Example 

Parses the loaded template html with the data set on the object with SetTag(String,String). If the loaded template is a XSLT file, the passed tags are converted into a XML-document which is applied with the loaded XSLT.
Syntax
'Declaration
 
Public Function Output() As String
public string Output()

Return Value

A merged string of the resulting html.
Remarks
Should only be called once for each instance of the template object. Use CommitLoop inside a loop.
Example
Full template exampleFull template exampleSimple template usage exampleSimple template usage 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();
        }

    }
}
'Load a template from /Files/Templates/MyFolder/MyTemplate.html
Dim t As New Template("MyFolder/MyTemplate.html")
'Set a tag value 
t.SetTag("MyTag", "Hello world!")
'Return the parsed template
Return t.Output
//Load a template from /Files/Templates/MyFolder/MyTemplate.html
Rendering.Template t = new Template("MyFolder/MyTemplate.html");
//Set a tag value 
t.SetTag("MyTag", "Hello world!");
//Return the parsed template
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

Send Feedback