gpt4 book ai didi

twig - TWIG中的动态 block 名称

转载 作者:行者123 更新时间:2023-12-04 06:26:03 25 4
gpt4 key购买 nike

我需要在模板中添加多个块,每个块都有不同的名称。

{% for item from items %}
{% block item.name %}sometext{% endblock %}
{% endfor %}

但是我得到了错误。我怎样才能做到这一点 ?

最佳答案

您可以使用block函数动态加载块。

{% for item in items %}
{{ block( item.name )|raw }}
{% endfor %}

Twig documentation for the block function

关于twig - TWIG中的动态 block 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7066365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com