Anna
Anna

Reputation: 55

jinja template for loop

I would like to break the for loop in jinja template/ I want to run it only once how should I do that.

{% for one in ones %}
  {{ one.column1 }}
{% endfor %}

I am getting 'ones' from the python code in different file and processing in jinja template. I want to print {{one.column1}} only once. column1 is one of the fields in the google app engine datastore entity. the value of column1 is same for all the iteration of the for-loop. Is there any other way to do this without for loop?

Upvotes: 1

Views: 581

Answers (1)

Dmytro Sadovnychyi
Dmytro Sadovnychyi

Reputation: 6201

If you really want break/continue support in jinja2 -- take a look on Loop Controls extension.

Just add it into "extensions" jinja's environment arguments:

'environment_args': {
  'autoescape': True,
  'extensions': [
    'jinja2.ext.loopcontrols',
  ],
  'auto_reload': False,
}

Upvotes: 2

Related Questions