我想知道为什么这行不通
{% set what = 'hate' %}
{% set byValue = 'like' %}
{{ 'I hate twig'|replace( { what : byValue } ) }}
它应该显示 I like twig
不是吗?
最佳答案
只需将键用括号括起来,Twig 就会将其视为变量:
{{ 'I hate twig'|replace({ (what): byValue }) }}
关于Twig 动态替换关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24288097/