Template tags are defined in the template layout which define placeholders, range blocks, formatting options etc. and generate desired Word documents after template processing.
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:
{{ds.value_path}[:formatter1(args1):formatter2(args2):..formatterN(argsN)]}
Example 1: {{ds.cities.name}:toupper()}
Here ds is the name of datasource and cities.name 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.
Result:
NEW YORK
LOS ANGELES
CHICAGO
HOUSTON
SAN FRANCISCO
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.
{{ds.UnitPrice}:hide-block-if-less(30):format(C)}
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 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:
{{#ds}}{{#ds.cities}}{{ds.cities.name}:toupper()}{{/ds.cities}}{{/ds}}
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}}{{ds.seas.name}:toupper()}{{/ds}}", use "\{{#ds}}\{{ds.seas.name}:toupper()}\{{/ds}}".
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)}}: {{ds.name}}{{if IsFirst(ds)}} (first){{else}}{{if IsLast(ds)}} (last){{endif}}{{endif}}
Here, "ds" is the name of the data source, and "ds.name" 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.
Result:
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.