这是什么“ - ”在jinja2模板引擎中呢? [英] What does this "-" in jinja2 template engine do?

查看:93
本文介绍了这是什么“ - ”在jinja2模板引擎中呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Wikipedia上找到这个例子: http://en.wikipedia.org/wiki/Jinja_%28template_engine%29

 {% - 对于item_list%中的项目} 
{{item}} {%if not loop.last%},{%endif%}
{% - endfor%}

什么是{% - for中的 - ?



另外,我在哪里可以找到jinja2示例(使用Google App Engine更好)?



非常感谢!

解决方案

它可以抑制额外的垂直间距,当您不希望循环的元素之间出现过多间距时通常会使用它。 b
$ b


如果您将减号( - )放在块的开始或结尾处(对于
,例如for标记),可以使用注释或变量表达式,你可以在该块之后或之前删除
空格


请参阅: http://jinja.pocoo.org/docs/templates/#whitespace-control


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!

解决方案

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

这篇关于这是什么“ - ”在jinja2模板引擎中呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆