在变量中显示变量 [英] Show variable inside variable

查看:24
本文介绍了在变量中显示变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以动态方式使用 twig 来生成模板,并且我想显示一个存储在数据库中的 twig 变量(值为 {{entity.id}}).

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 %}

parameter.value 应该显示 1(当前实体的 id),但它显示 {{entity.id}}

The parameter.value should show 1 (the id of the current entity), but it shows {{entity.id}}

在 php 中是否有等效于 eval 的 twig?

Is there equivalent to eval in php for twig?

推荐答案

目前有一些好心人正在开发这个扩展,但我认为它还没有被拉入主分支.看起来我们很快就会有一个EvaluateString"twig 函数.这是:

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

这篇关于在变量中显示变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆