从 Twig 数组中获取特定值(使用 Symfony2) [英] Getting a specific value from Twig array (using Symfony2)

查看:33
本文介绍了从 Twig 数组中获取特定值(使用 Symfony2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我可以这样做:

{% for x in data %}
    {{ x.label }}: {{ x.value }}<br />
{% endfor %}

但我想做这种事情来获得一个特定的价值:

But I want to do this kind of thing to get one specific value:

{{ data['label' }}

我不知道怎么做,但它一定是可能的.

I can't see how to do it, but it must be possible.

推荐答案

http://twig.sensiolabs.org/doc/functions/attribute.html

{{ attribute(data,'label') }}

{{ attribute(data,'label') }}

这篇关于从 Twig 数组中获取特定值(使用 Symfony2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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