Jinjava tags

Tags are jinjava-based functions created by Synerise. They enable easier access to some jinjava expressions, with additional or alternative logic tailored to the needs of our clients.

AutoEscape

Autoescape the tag’s contents.

{% autoescape %}
    <!--Code to escape-->
{% endautoescape %}

Call

In some cases, it can be useful to pass a macro to another macro. For this purpose, you can use the special call block.

This is a simple dialog rendered by using a macro and a call block:

{% macro render_dialog(title, class='dialog') %}
    <div class="{{ class }}">
        <h2>{{ title }}</h2>
        <div class="contents">
            {{ caller() }}
        </div>
    </div>
{% endmacro %}

{% call render_dialog('Hello World') %}
    This is a simple dialog rendered by using a macro and
    a call block.
{% endcall %}

It’s also possible to pass arguments back to the call block. This makes it useful as a replacement for loops. Generally speaking, a call block works exactly like a macro, but it doesn’t have a name. Here’s an example of how a call block can be used with arguments:

{% macro dump_users(users) %}
    <ul>
    {% for user in users %}
        <li>
            <p>{{ user.username|e }}</p>
            {{ caller(user) }}
        </li>
    {% endfor %}
    </ul>
{% endmacro %}

{% call(user) dump_users(list_of_user) %}
    <dl>
        <dl>Realname</dl>
        <dd>{{ user.realname|e }}</dd>
        <dl>Description</dl>
        <dd>{{ user.description }}</dd>
    </dl>
{% endcall %}

Cycle

The cycle tag can be used within a for loop to cycle through a series of string values and print them with each iteration.

Parameters:

Type Required Description
list yes A comma-separated list of strings to print with each iteration. The list will repeat if there are more iterations than string parameter values.

In the example below, the classes odd and even are applied to posts in a listing:

{% for content in contents %}
    <div class="post-item {% cycle 'odd','even' %}">
        Blog post content
    </div>
{% endfor %

If, else if, else

Outputs inner content if expression evaluates to true, otherwise evaluates elif blocks, finally outputting the content of the else block present (if no elif block evaluated to true).

{% if number <= 2 %}
    Variable named number is less than or equal to 2.
{% elif number <= 4 %}
    Variable named number is less than or equal to 4.
{% elif number <= 6 %}
    Variable named number is less than or equal to 6.
{% else %}
    Variable named number is greater than 6.
{% endif %}

For

Outputs the inner content for each item in the given iterable.

Example:

{% set names = ["John", "Kate", "Bob"] %}

{% for item in names %}
    Hello, {{ item }}!
{% endfor %}

Ifchanged

Outputs the tag contents if the given variable has changed since a prior invocation of this tag.

{% ifchanged variable %}
    <!-- Code to execute if the variable has changed -->
{% endifchanged %}

Macro

Macros allow you to print multiple statements with a dynamic value or values.

Basic macro syntax:

<!-- Defining the macro -->
{% macro name_of_macro(argument_name, argument_name2) %}
    {{ argument_name }}
    {{ argument_name2 }}
{% endmacro %}

<!-- Calling the macro -->
{{ name_of_macro("value to pass to argument 1", "value to pass to argument 2") }}

Example of a macro used to print CSS3 properties with the various vendor prefixes.

{% macro trans(value) %}
    -webkit-transition: {{value}};
    -moz-transition: {{value}};
    -o-transition: {{value}};
    -ms-transition: {{value}};
    transition: {{value}};
{% endmacro %}

The macro can then be called like a function. The macro is printed for anchor tags in CSS.

a { {{ trans("all .2s ease-in-out") }} }

Print

Echoes the result of the expression.

Examples:

{% set string_to_echo = "Print me" %}

{% print string_to_echo %}

{% print -65|abs %}

Raw

Processes all inner expressions as plain text.

{% raw %}
    The personalization token for a contact's first name is {{ contact.firstname }}
{% endraw %}

Set

Assigns the value or result of a statement to a variable.

Basic syntax:

{% set variableName = variableValue %}

The value can be a string, a number, a boolean, or a sequence.

Example:

Set a variable and print the variable in an expression:

{% set primaryColor = "#F7761F" %}

{{ primaryColor }}

You can combine multiple values or variables into a sequence variable.

{% set var_one = "String 1" %}

{% set var_two = "String 2" %}

{% set sequence = [var_one, var_two] %}

Unless

Unless is a conditional just like ‘if’, but works on an inverse logic.

{% unless x < 0 %}
    x is greater than zero
{% endunless %}
😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

Close modal icon Placeholder alt for modal to satisfy link checker