Agents can populate a custom Word or Excel document. When an Output Template is added to an Agent, the Agent will replace placeholders in the file with results from its prompts. All styles, formatting, formulas, and macros will be preserved.

Guided Tour

This guide assumes that you are already familiar with the basics of creating an Agent and setting up prompts. If you’d like to follow along, the files used in this guide may be downloaded here.

Setting up a Template

Creating a Template File

The template file allows you to insert values from an Agent Run. The template generator will look for placeholders in the template file surrounded by curly brackets and a space, such as {{ prompt_name }}. Note that placeholders must be lowercased, with spaces and special characters replaced with an underscore character (_). Kolena will preserve the font and format of the placeholders. For example, if your placeholder is {{ company_name }} in bolded, size 24, Times New Roman and your Agent Run has Company Name extracted as Kolena Inc, the placeholder will be replaced with Kolena Inc, also in bolded, size 24, Times New Roman. All values in the template files that are not in placeholders (such as text, images, and borders) will be preserved as is.

Uploading a Template File

Now that we’ve created a template file, we can upload it to our Agent:
  1. Navigate to the Agent for which the template applies
  2. Click on the Output card to fully expand it
  3. Click on the “Set Output Template” button
  4. Drag and drop the template file onto the file upload
  5. Hit Submit
With this, we’ve uploaded our first template!

Mapping Prompts to Placeholders

By default, Kolena will map prompts to placeholders by converting the prompt names to lowercase and replacing spaces and special characters with underscores. You can see this as the placeholder whenever you click into the details for the prompts. You can change the placeholder by editing the prompt. This allows you to map a prompt’s value to one that might not necessarily match the name exactly.

Templating the Output File Name

Placeholders can also be used to populate the output file name by using the same curly-bracket syntax in the file name of the template. For example, if you have a lease abstract template and want each file to be named using the property address (“123 Example St - Lease Abstract.pdf”):
  1. Ensure your Agent has a prompt that returns the property address (suppose its placeholder is property_address)
  2. Name your lease abstract template file {{ property_address }} - Lease Abstract.docx
  3. Upload this template file to your Agent
When an output is downloaded manually or sent to a destination, the placeholder in the file name will be replaced with the real property address.

Using the Template

Once you’ve uploaded and configured your template, you can use it for direct downloads and for automated connections to destinations.

Downloading the Output

You can directly download the templated output from the Reports page for a given Agent Run:
  1. Navigate to the desired Agent Run
  2. Click into the “Report” tab
  3. Click on the (Download) icon
  4. Select your desired template from the download menu
Word Output Templates may be downloaded as either an editable docx, or a generated pdf report.

Configuring a Destination

You can also specify a template for export with a Destination connection. Simply go to the Connections page in Kolena, create or edit an existing Destination, and set your template as the “Fill Template” under the “Export Options” section.

Advanced

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.

Tables

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.

Forms

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.

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 }}

Excel Number Cells

This feature is experimental
Numbers in the Excel Output Templates may show as text cells which can break formulas. To fix this, instead of {{ prompt_name }} you can use {%xv prompt_name %} in your Excel template file, such as {%xv item["Amount"] %}.