Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this "-" in jinja2 template engine do?

I am learning jinja2 because Google App Engine recommends it.

I found this example on Wikipedia: http://en.wikipedia.org/wiki/Jinja_%28template_engine%29

  {%- for item in item_list %}     {{ item }}{% if not loop.last %},{% endif %}   {%- endfor %} 

What is the "-" in "{%- for"?

Also, where can I find jinja2 examples (better with Google App Engine)?

Thanks a lot!

like image 321
Gaby Solis Avatar asked Aug 05 '12 02:08

Gaby Solis


People also ask

How are variables in Jinja2 templates specified?

A Jinja template doesn't need to have a specific extension: . html , . xml , or any other extension is just fine. A template contains variables and/or expressions, which get replaced with values when a template is rendered; and tags, which control the logic of the template.


1 Answers

It suppresses extra vertical spacing, commonly used when you don't want excessive spacing between elements you're looping through.

If you put an minus sign (-) to the start or end of a block (for example a for tag), a comment or variable expression you can remove the whitespaces after or before that block

See: http://jinja.pocoo.org/docs/templates/#whitespace-control

like image 156
hyperslug Avatar answered Oct 04 '22 01:10

hyperslug