例如代码:
{% set sites = [
{name:"StackOverFlow",url:"https://stackoverflow.com/"},
{name:"ask-Ubuntu",url:"https://askubuntu.com/"}
] %}
{% for site in sites %}
<a href="{{site.url}}">{{site.name}}</a>,
{% endfor %}
结果将如下所示:
StackOverFlow,ask-Ubuntu,
我的问题是如何最终防止不必要的,
?
答案 0 :(得分:0)
您可以使用loop.last
-表示最后一次迭代(docs)的布尔值
{% set sites = [
{name:"StackOverFlow",url:"https://stackoverflow.com/"},
{name:"ask-Ubuntu",url:"https://askubuntu.com/"}
] %}
{% for site in sites %}
<a href="{{site.url}}">{{site.name}}</a>{% if not loop.last %}, {% endif %}
{% endfor %}