jinja macros code example

Example 1: jinja if

{% if 'priority' in data %}
    

Priority: {{ data['priority'] }}

{% endif %}

Example 2: jinja if else

{% if "Already" in RepoOutput[RepoName.index(repo)] %}
    {% set row_class = "good" %}
{% else %}
    {% set row_class = "error" %}
{% endif %}
 {{ RepoOutput[RepoName.index(repo)] }} 

Example 3: jinja macro import

# This is how you define the macro
# This is in the file "Input_Block"
{% macro input(name, value='', type='text', size=20) -%}
    
{%- endmacro %}

# Import from the file and set a contextual name
{% import 'Input_Block' as emailBlock %}
{{ emailBlock.input("user input") }}

Tags:

Misc Example