嫩枝数组访问 [英] Twig array access

查看:210
本文介绍了嫩枝数组访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印出来传递给树枝模板变量的值。我使用这个code:

I'm trying to print out value of the variable passed to the twig template. I'm using this code:

{{naziv [0]}} 指数是0,因为传递的数组只有一个元素。提到code会产生以下错误:

{{ naziv[0] }} Index is 0 because passed array has only one element. Mentioned code produces following error:

0键与键称号数组中不存在...

Key "0" for array with keys "title" does not exist in...

但是当我使用循环是这样的:

but when I use for loop like this:

{% for key,value in naziv %}
{{ value }}
{% endfor %}

我得到我想要的东西。

I get what I want.

这有什么错 {{naziv [0]}}

推荐答案

根据的var_dump 的阵列(1){[称号 ] =>串(11)SpaceVision}

您应该获得这样的数组: {{naziv ['标题']}}

You should access your array in this way: {{ naziv['title'] }}.

您的阵列的关键是联想,而不是一个数字索引数组。这就是为什么你不能使用 naziv [0]

The key of your array is associative and not a numerically indexed array. That is why you cannot use naziv[0].

您也可以使用: {{} naziv.title} 藏汉

查看文档

这篇关于嫩枝数组访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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