显示变量内的变量

发布于 2025-01-06 11:10:13 字数 297 浏览 2 评论 0原文

我以动态方式使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始于初秋 2025-01-13 11:10:13

目前有些人正在开发这个扩展,但我认为它还没有被拉到主分支中。看起来我们很快就会有一个“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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文