jinja2 functions code example

Example 1: jinja if

{% if 'priority' in data %}
    <p>Priority: {{ data['priority'] }}</p>
{% endif %}

Example 2: jinja if else

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

Example 3: templates python

from string import Template
poem = Template('$x are red and $y are blue')

print(poem.substitute(x='roses', y='violets'))
#>>>roses are red and violets are blue

Tags:

Misc Example