如何评估树枝表达 [英] How to evaluate twig expression

查看:18
本文介绍了如何评估树枝表达的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向后弯腰解决这个问题,但还没有运气.

I've bend over backwards to solve this one, but no luck yet.

{% for field in fields %}
    {{dump(form.children.~(field.label)~.vars.value)}}
{% endfor %}

你在树枝中看到上面的代码了吗?我如何让 Twig 先评估 (field.label),然后评估表达式的其余部分((form.children.Age.vars.value)).现在它会抛出树枝语法错误

U see the above code in twig? How do I get twig to evaluate (field.label) first and then evaluate the rest of the expression((form.children.Age.vars.value)). For now it throws the twig syntax error

Expected name or number.

有什么想法吗?

推荐答案

您可以使用:

{% for field in fields %}
    {{ dump(form.children[field.label].vars.value) }}
{% endfor %}

干杯

这篇关于如何评估树枝表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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