Document Solutions for Word
Report Templates / Template Configuration / Template Tags
In This Topic
    Template Tags
    In This Topic

    Template tags are defined in the template layout which define placeholders, range blocks, formatting options etc. and generate desired Word documents after template processing.

    Value Tag

    The value tags specify placeholders which are replaced by actual data from the data source after template processing. These can be defined by using the below syntax:


    Example 1:  {{}:toupper()}

    Here ds is the name of datasource and is full value path in data source. The 'toupper' formatter converts all strings to their upper case representation. After processing, the template tag expands automatically and produces a list of every city in every object.



    Example 2: You can also use multiple formatters in a single tag by chaining them together. In such cases, the result of one formatter serves as an input to the next formatter. The below value tag hides all records where UnitPrice is less than 30 and formats the resultant values as currency.


    Short Notation for Value Tag

    As a single data source can be used in a template, you can also specify the value tag in a short format by omitting the name of datasource. For example:

    Range Tag

    Range tags are used when you want to define a strict area for repeating a section of data object. The content in this section is copied for every enumerated object. If omitted, the template automatically calculates the start and end of a repeating block and may produce unwanted results.

    Open and close tags can be used to resolve the start and end of a repeating section of data.

    If 'ds' is the name of a data set:

    For example, a fully qualified template tag to list all cities in uppercase from the data source will look like:


    Note: A Root template is a part of document which contains template tags and is covered by {{#ds}}...{{/ds}} tags, where ds is name of used datasource. A single Root template is supported per Word document.
    Note: Sometimes, you may need to exclude some template tags from processing to make them appear as they are in the document (for example, to show a tag and the result of processing it side by side). DsWord allows you to do it by adding a backslash (\) immediately before the opening curly braces of the tag. To insert a backslash and still process the tag, use two backslashes. The backslashes have no special meaning to the template engine except when immediately preceding a template tag.

    Note that when escaping several related template tags, you must escape them all; otherwise, the template engine will encounter an invalid template construct and throw an exception. For example, to escape the construct "{{#ds}}{{}:toupper()}{{/ds}}", use "\{{#ds}}\{{}:toupper()}\{{/ds}}".

    State Functions

    The IsFirst, IsLast, and Index template state functions enable you to identify the first and last iteration, as well as the index of the current iteration in a collection.

    IsFirst returns true when the index of the current iteration is zero. IsLast returns true when the index of the current iteration is Count-1 in the collection items. Index returns the index of the current iteration in a collection.

    Example: Record {{calc Index(ds)+1}} of {{calc Count(ds)}}: {{}}{{if IsFirst(ds)}} (first){{else}}{{if IsLast(ds)}} (last){{endif}}{{endif}}

    Here, "ds" is the name of the data source, and "" is the name field in the data source. "calc Index(ds)+1" gets the index of the current iteration in the collection and adds one to it. "calc Count(ds)" gets the total number of iterations in the collection. "if IsFirst(ds)" checks if the current index is the first index of the collection, and "if IsLast(ds)" checks if the current index is the last index of the collection.


    Record 1 of 5: Australasian Mediterranean Sea (first)

    Record 2 of 5: Philippine Sea

    Record 3 of 5: Coral Sea

    Record 4 of 5: South China Sea

    Record 5 of 5: Sargasso Sea (last)

    For more information on how to implement state functions, see Collection State.