Skip to main content
For Word / CSV Output Templates, Kolena uses the Jinja templating syntax with the docxtpl engine. This tooling allows support for more advanced rendering, such as with tables and conditionally displaying values.

Scalar Outputs

To include scalar outputs (i.e. Text, Number, True/False, Classification) in your Word or CSV template, simply write the placeholder name in curly brackets. For example, if you have a Prompt named “Company Name” with the placeholder company_name, you can write:
{{ company_name }}

Form Outputs

You can treat the values of a Kolena form Prompt as key value pairs. When using form data in templates, you can access individual fields using bracket notation:
{{ person_info["Name"] }} is {{ person_info["Age"] }} years old.
If you have a form Prompt with the template placeholder person_info with the fields ["Name", "Age", "Email", "Phone"], the unused fields are ignored.

Table Outputs

You can loop over the values of a Kolena table Prompt.
Date                          Payee                   Payment Value
{%tr for item in payments %}
{{ item["Payment Date"] }}    {{ item["Paid To"] }}   {{ item["Amount"] }}
{%tr endfor %}
In this case, if my {{ payments }} Prompt gave me a table with details on individual payments, the above syntax would allow me to replicate that table (with formatting) into my templated output. Note that the field being retrieved from the item must match the Prompt’s table columns but the header columns used in the template are free to differ.

Referencing Specific Table Rows

If you wish to reference a specific row from a table Prompt, you can do so using bracket notation. For instance, to reference the first row’s Payment Date from a payments table Prompt, you can use:
{{ payments[0]["Payment Date"] }}
Be aware that accessing a row which does not exist will result in an error during template rendering. To avoid this, you can use a conditional to check that the row exists before accessing it. For example:
{{ (payments[0]["Payment Date"] if payments|length > 0 else '') }}

Conditionally Displaying Sections

You can conditionally display a certain section from the template file based on Prompt values using the if syntax:
{%p if tax_value > 0 %}
Due to local regulations, a tax amount of ${{ tax_value }} is owed.
{%p endif %}
The above blurb about tax value will only be displayed if the {{ tax_value }} Prompt retrieves a number greater than zero, and will otherwise not be displayed in the templated output.

Reserved Placeholders

The following placeholders are automatically provided and can be used in templates:
  • {{ _kolena_date }}: Date of the Agent Run in UTC, formatted as YYYY-MM-DD.
  • {{ _kolena_agent }}: Name of the Agent running the Prompt.
The following placeholders are reserved for internal use by Kolena and cannot be used in templates. They will not be rendered in the final output:
  • {{ sheet_name }}
  • {{ tpl_name }}