Engageable templating language is used to present Excel and Word documents or HTML based on answers or tag values within a workflow. Engageable provides access to the TWIG templating language within certain areas of the application.
See also: Template Variables, Office Templates
To use the template language within a html field use the code editor button.
Example
<ul>
{% for value in tags.session_date_val_list %}
<li>
{% if value > 0 %}
{{ value|date("d/m/Y") }}
{% else %}
N/A
{% endif %}
</li>
{% endfor %}
</ul>
Where can I use it?
Advanced Content can be used in the following locations:
- Workflow, module, task and question descriptions.
- HTML Reports
- Excel Reports
- Question Text
- Question Descriptions
- Website content blocks
Engageable uses the twig templating language. We have documented some of the relevant features here. For further information you can refer to the Twig Manual
Variables
Variables may have attributes or elements you can access. You can use a dot (.) to access attributes of a variable
{{ foo.bar }}
{{ foo['bar'] }}
When the attribute contains special characters (like - that would be interpreted as the minus operator), use the attribute function instead to access the variable attribute:
{# equivalent to the non-working foo.data-foo #}
{{ attribute(foo, 'data-foo') }}
It's important to know that the curly braces are not part of the variable but the print statement. When accessing variables inside tags, don't put the braces around them.
If a variable or attribute does not exist, you will receive a null value
Filters
Variables can be modified by filters. Filters are separated from the variable by a pipe symbol (|) and may have optional arguments in parentheses. Multiple filters can be chained. The output of one filter is applied to the next.
The following example removes all HTML tags from the name and title-cases it:
{{ name|striptags|title }}
Filters that accept arguments have parentheses around the arguments. This example will join a list by commas:
{{ list|join(', ') }}
To apply a filter on a section of code, wrap it in the filter tag:
{% filter upper %}
This text becomes uppercase
{% endfilter %}
For mor information about the available filters see the Twig Filters
Control Structure
A control structure refers to all those things that control the flow of a program - conditionals (i.e. if/elseif/else), for-loops, as well as things like blocks. Control structures appear inside {% ... %} blocks.
For example, to display a list of users provided in a variable called users, use the for tag:
<h1>Members</h1>
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
The if tag can be used to test an expression:
{% if users|length > 0 %}
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% endfor %}
</ul>
{% endif %}
To learn more about the built-in tags see the Twig Tags.