Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add ifchanged loop variable #133

Closed
hypertexthero opened this Issue · 3 comments

3 participants

@hypertexthero

Please add the ifchanged loop variable that is available in the original Jinja to the default extensions.

@mitsuhiko
Owner

That's a very inefficient way to do this. That's why it was removed :)

@mitsuhiko mitsuhiko closed this
@jheasly

@mitsuhiko Could you point to an efficient example of how to achieve this? A function or macro or somesuch? Thanks for any help you can provide!

@jheasly

To answer my own question, discovered Jinja2 Assignments, so if you want to ifchanged on baz.category:

{$ for baz in foo %}

    {% if baz.category != variable_watcher %}

        {# Do whatever when there's been a change here. #}
        {% baz.category %}
        {% set variable_watcher = baz.category %}

    {% else %}

        {# Do whatever when there's no change here. #}
        {% baz.category %}

    {% endif %}

{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.