This is the first built-in variable in TextTemplate.

It is declared to be of type object, but can contain any type of object or structure that you can pass to it. Its purpose is to allow you to pass information from your program into the template, to control what and how the template should produce output.

Here's an example template using the templateState variable:

<%@ language C#v3.5 %>
<%@ using System.Collections.Generic %>
    List<string> names = (List<string>)templateState;
    foreach (var name in names)
Hello, <%= name %>.

And here's some C#-code that uses it:

using (var template = new Template())
    template.Content = templateContent;
    var output = template.Execute(new List<string>

Note You must cast the variable to whatever type the template expects the value to be.

Last edited Jan 20, 2011 at 10:44 PM by lassevk, version 1


No comments yet.