symfony twig 数组键显示

symfony twig array key display

我正在尝试使用数组索引从数据库中获取数据,但是我不想重复。

内容table:

|id|      content          |active
|1|this is first content   |yes
|2| This is secound Content| yes

Controller.php:

$em = $this->getDoctrine()->getManager();
$entities= $em->getRepository('TestCMSBundle:Content\Content')->GetContents();

return $this->render('TestCMSBundle:Default:index.html.twig', array('entities' => $entities));

我的树枝:

{{ entities.content[0] }}

一些其他内容....等等等等

{{ entities.content[1]}}

但是我好像看不懂内容

错误: "content" 键为“0, 1”的数组的键 TestCMSBundle:index 中不存在。html.twig 第 80

我不想像这样迭代循环:

{% for entity in entities %}
{{ entity.content}}
{%endfor%}

您应该使用点而不是括号:

entities.0.content