Skip to content Skip to sidebar Skip to footer

Nested Block And For Loop In A Jinja Template Block

Trying to use nested block and for loop in a Jinja template block setup. {% block main %}

Solution 1:

You can't treat Jinja syntax as Python syntax. It's not the same thing. Keep your for tag separate from assignment (set) tags:

    {% for user in list_users %}
        {% set t_id_user = user[0][0] %}
        {% set t_sec_level = user[2][0] %}

Note that there isn't even a : at the end of the for ... in ... syntax! Also you don't need to call str() here, leave that to Jinja to convert to strings for you; anywhere you use {{ t_id_user }} or {{ t_sec_level }} the value will be converted to a string anyway.

Here is the complete template:

<table>
{% block main %}
    {% block main_nested_b scoped %}
    {% for user in list_users %}
        {% set t_id_user = user[0][0] %}
        {% set t_sec_level = user[2][0] %}
<tr><td><ahref='/usersEdit?id_user={{ t_id_user }}'class='onwhite'>edit</a></td></tr>
    {% endfor %}
    {% endblock main_nested_b %}
{% endblock main %}
</table>

Post a Comment for "Nested Block And For Loop In A Jinja Template Block"

user iduser sec level