Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 小枝模板:在连接函数中添加html_Arrays_Templates_Join_Symfony_Twig - Fatal编程技术网

Arrays 小枝模板:在连接函数中添加html

Arrays 小枝模板:在连接函数中添加html,arrays,templates,join,symfony,twig,Arrays,Templates,Join,Symfony,Twig,我可以使用以下方法获取与帖子相关的所有标签: {{ post.tags | join(', ') }} 它将表明: tag1, tag2, tag3, etc 我怎样才能让这些标签成为链接,而不仅仅是文本? 我的意思是: 、等 我是否被迫使用foreach()、单独显示标记并手动添加逗号 谢谢大家! 手动操作,并不复杂 {% for tag in post.tags %} <a href="{{tag}}.php">{{tag}}</a>, {% endfo

我可以使用以下方法获取与帖子相关的所有标签:

{{ post.tags | join(', ') }}
它将表明:

tag1, tag2, tag3, etc
我怎样才能让这些标签成为链接,而不仅仅是文本? 我的意思是:

、等
我是否被迫使用foreach()、单独显示标记并手动添加逗号


谢谢大家!

手动操作,并不复杂

{% for tag in post.tags %}
    <a href="{{tag}}.php">{{tag}}</a>,
{% endfor %}
{%for post.tags%}
,
{%endfor%}

是,按照Carlos说的做,检查最后一个条目,这样你就不会在末尾有一个lonley逗号,比如:
tag1,tag2

{%for post.tags%}
{%if loop.last==false%},{%endif%}
{%endfor%}
这将导致:
tag1,tag2

就像join一样。

是的,结尾是孤独的逗号,世界上最古老的问题:-)
{% for tag in post.tags %}
    <a href="{{tag}}.php">{{tag}}</a>,
{% endfor %}
{% for tag in post.tags %}
    <a href="{{tag}}.php">{{tag}}</a>{% if loop.last == false %},{% endif %} 
{% endfor %}