What does this “-” in jinja2 template engine do?

大城市里の小女人 提交于 2019-12-18 11:45:36

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/11813422/what-does-this-in-jinja2-template-engine-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!