trim_blocks not working for a recursive loop #87

Open
Sirtea opened this Issue Jan 12, 2012 · 0 comments

Projects

None yet

1 participant

Sirtea commented Jan 12, 2012

(I'll put the Flask view code, as I have no idea reproducing the code only with jinja2)

I have a code that renders some elements that are in a tree fashion distribution, and a recursive loop in jinja2 (listed at the bottom). As I activated the trim_blocks, lines with only tags are removed, rather than left empty. No surpise here.
Following the docs (http://jinja.pocoo.org/docs/templates/#whitespace-control), there is no need to use the minus sign to manually supress the newlines.

But when I use the recursive for (http://jinja.pocoo.org/docs/templates/#list-of-control-structures) the white spaces are not supressed as I would, but I can add the minus sign to supress, so this is a VERY minor issue. Look at the code below.

¿Is this behaviour correct?

view: myapp.py

from flask import Flask, render_template

app = Flask(name)
app.jinja_env.trim_blocks = True

@app.route('/')
def hello():
data = [['a', 'b'], 'c', [['d', 'e'], 'f']]
return render_template('hello.html', data=data)

template buggy: hello.html

{% for element in data recursive %}
{% if element is string %}
<p>{{ element }}</p>
{% else %}
{{ loop(element) }}
{% endif %}
{% endfor %}

template ok: hello.html

{% for element in data recursive %}
{% if element is string %}
<p>{{ element }}</p>
{% else %}
{{ loop(element) -}}
{% endif %}
{% endfor %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment