Method: FillTemplate ( … )
Generates content based on a template and a Data Source, by looping through every Input-row in the Data Source and applying the template to each row, e.g. to create a list of items with various information about each item.
Syntax
string FillTemplate( string template, string sourceName,
string separator = "\r\n", string filter = "", string sort = "" )
Method Parameters
string | The template to use for each row in the Data Source. |
string | Name of the Data Source containing the rows to iterate through and apply content from to the template. The Data Source must be of the Table type. |
string | The content that is used to separate each iteration of the template. |
string | Optional expression used to filter rows, similar to SQL. |
string | Optional value specifying the column to sort and direction. |
Example
Below example shows how to define a template in html-format, and include lookups of values from the input-row, such as {id} and {Value} and {ShortText}.
string template = "<a href='http://www.perfion.com?pid={id}'>{Value}</a><br><i>{ShortText}</i><br>";
string message = FillTemplate( template, "Items", "<br>" );
It is also possible to reference values from variables by writing e.g. {=$WebRoot} to lookup the value of a globally defined variable $WebRoot.
To make editing the template easier, it can be stored in a variable and defined using e.g. the SET command, and instead reference the variable in the above example code.