Jinja2 Syntax

Learn the most common syntax for customizing Word templates in PlexTrac

This section covers the basics of Jinja2 syntax that are most relevant for exporting reports from PlexTrac to Word.

For a complete reference of Jinja2 syntax, visit that official documentation here: http://jinja.pocoo.org/docs/2.10/‚Äč

Text Content

Adding text content to a Word template is relatively straightforward with Jinja2 syntax. I the example below, we demonstrate how to add the title of the Report to a Word template.

Note the title is a field in the REPORT_INFO object. This is the common pattern for referencing text content in a Word template.

{{ REPORT_INFO.title }}

If, Else, Elif

PlexTrac understands it is critical to support the ability to conditionally display data in an exported reported. Conditions are handled by if, else, and elif syntax in Word templates.

The following example demonstrates how an if statement might be used to display a paragraph.

{%p if REPORT_INFO.title == "Title" %}
{{ REPORT_INFO.title }}
{%p endif %}

This example demonstrates how an elif statement might be used to display a paragraph. Note that the elif statement is closed by the same endif tag as the if statement in which it is encapsulated.

{%p elif REPORT_INFO.title == "Title" %}
{{ REPORT_INFO.title }}
{%p endif %}

Finally, this example demonstrates how an else statement might be used to display a paragraph. Again, note that the else statement is closed by the same endif tag as the if and elif statements in which it is encapsulated.

{%p else %}
{{ REPORT_INFO.title }}
{%p endif %}

For-Loop

PlexTrac supports the ability to loop through data in the Word template. The most common use case is to loop through findings. The example below demonstrates how to loop through each finding and display its criticality. Note the loop is closed by the endfor tag.

{%p for finding in FINDINGS %}
{{ finding.CRITICALITY }}
{% endfor %}