Jinja Cheatsheet

We can use Jinja templating language in Response Item Template and in Response Item Template for Selection (under Advanced Response Configuration) fields in DSW. Here you can get a basic overview of what can be achieved with Jinja.

For more information about Jinja templating language, visit the official Jinja documentation.

Basic Syntax

These are the basic Jinja elements:

Formatting Jinja Syntax

Variable

{{ variable }}

If Statement

{% if condition %} ... {% endif %}

If-Else Statement

{% if condition %} ... {% else %} ... {% endif %}

For Loop

{% for item in items %} ... {% endfor %}

Comment

{# This is a comment #}

Note

We can also construct logo and link available in the legacy version of API Integration directly in the Response Item Template.

Whitespace Control

By default, Jinja keeps whitespace (spaces, tabs, newlines) around tags. You can use the - (dash) modifier inside delimiters to trim or strip it.

Formatting Jinja Syntax

Default Behavior

{% if condition %}
  ...
{% endif %}

Trim Leading Whitespace

{%- if condition %} ... {%- endif %}

Trim Trailing Whitespace

{% if condition -%} ... {% endif -%}

Trim Both Sides

{%- if condition -%} ... {%- endif -%}

Loop Example

{% for item in items -%}
{{ item }}
{%- endfor %}

Note

Use the - (dash) inside tag delimiters to remove whitespace. This is particularly helpful when generating compact text or code (e.g., JSON, YAML, Markdown).