Git Product home page Git Product logo

Comments (14)

mitsuhiko avatar mitsuhiko commented on May 22, 2024

I will keep it in mind for the new compiler backend, but in the current one that is not possible to achieve for performance reasons.

from jinja.

medwards avatar medwards commented on May 22, 2024

I'd like to see this too.

from jinja.

palmkevin avatar palmkevin commented on May 22, 2024

+1

from jinja.

smatthews1999 avatar smatthews1999 commented on May 22, 2024

I would like to see this too.

I'm trying to perform simple running totals in some generated data..and that functionality is what I need.

from jinja.

smeggingsmegger avatar smeggingsmegger commented on May 22, 2024

+1

from jinja.

alexcasalboni avatar alexcasalboni commented on May 22, 2024

+1

from jinja.

ruiposse avatar ruiposse commented on May 22, 2024

+1

I also think that this behaviour should be unacceptable:

    {% set first_run = True %} {% for i in range(3) %}
      {% for j in range(3) %} {% if first_run %} {% set first_run = False %}
    • {{ i }}, {{ j }}
    • {% endif %} {% endfor %}
    {% endfor %}

This will output 3

  • tags, but it should output only one.
    The variable resets after each outer loop run, even though it was declared OUTSIDE of all loops.

    I can't see how this would be expected behaviour. Is this a bug ?

  • from jinja.

    ruiposse avatar ruiposse commented on May 22, 2024

    +1

    I also think that this behaviour should be unacceptable:

    <ul>
      {% set first_run = True %}
      {% for i in range(3) %}
      <ul>
        {% for j in range(3) %}
        {% if first_run %}
        {% set first_run = False %}
        <li>{{ i }}, {{ j }}</li>
        {% endif %}
        {% endfor %}
      </ul>
      {% endfor %}
    </ul>
    

    This will output 3 <li> tags, but it should output only one.

    The variable resets after each outer loop run, even though it was declared OUTSIDE of all loops.
    I can't see how this would be expected behaviour. Is this a bug ?

    from jinja.

    skuda avatar skuda commented on May 22, 2024

    +1

    from jinja.

    thaddeusmt avatar thaddeusmt commented on May 22, 2024

    This would very useful when templating JSON files. +1

    from jinja.

    dpgaspar avatar dpgaspar commented on May 22, 2024

    +1

    from jinja.

    dlenski avatar dlenski commented on May 22, 2024

    Me too, could really use an override and it'd be great if the template designer docs explicitly mentioned this behavior!

    I had to work with some data in an (admittedly horrible) format and was puzzled at why the followed pre-pass didn't work...

    {% set last_one = none %}
    {% for row in rows %}
        {% set last_one = row.field %}
    {% endfor %}
    

    I agree with @ruiposse's comment that having a variable first set outside all loops reset itself inside them is very unexpected.

    from jinja.

    t2y avatar t2y commented on May 22, 2024

    +1

    from jinja.

    mitsuhiko avatar mitsuhiko commented on May 22, 2024

    I'm going to close this. This cannot work in all cases in Jinja2 and I do not really wish on supporting it.

    from jinja.

    Related Issues (20)

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.