显示变量内的变量
我以动态方式使用 twig 来生成模板,我想显示存储在数据库中的 twig 变量(值为 {{entity.id}})。
{%- for parameter in reportParameters%}
{{ parameter.name }} : {{ parameter.value }}
{%- endfor %}
parameter.value应该显示1(当前实体的id),但它显示{{entity.id}}
php中的twig是否有相当于eval的东西?
I am using twig in a dynamic way to generate template and I want to show a twig variable that is stored in database (the value is {{entity.id}}).
{%- for parameter in reportParameters%}
{{ parameter.name }} : {{ parameter.value }}
{%- endfor %}
The parameter.value should show 1 (the id of the current entity), but it shows {{entity.id}}
Is there equivalent to eval in php for twig?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前有些人正在开发这个扩展,但我认为它还没有被拉到主分支中。看起来我们很快就会有一个“EvaluateString”twig 函数。这是:
https://github.com/fabpot/Twig-extensions/pull/53
Some kind folk are working on this extension at the minute but I don't think it's been pulled into the master branch yet. It looks as though we're going to have an "EvaluateString" twig function soon. Here it is:
https://github.com/fabpot/Twig-extensions/pull/53