从数组渲染单个数据

问题描述 投票:0回答:1

{{dump(states)}}这会返回

FormView {#5921 ▼
  +vars: array:33 [▼
    "value" => []
    "attr" => []
    "form" => FormView {#5921}
    "id" => "States"
    "name" => "States"
    "full_name" => "States"
    "disabled" => false
    "compound" => false
    "method" => "POST"
    "action" => ""
    "preferred_choices" => []
    "choices" => array:41 [▶]
    ]
  +parent: FormView {#5618 ▶}
  +children: []
  -rendered: false
  -methodRendered: false
}

我想显示选择状态 - 选项35.how从数组中选择哪一个有41个选择?

php twig symfony-3.2
1个回答
1
投票

您可以使用。访问twig中的数组成员。或[]语法。

因此,您选择的数组的第35个选项可以在树枝中呈现:

{{ states.vars.choices[34] }}

有关如何访问twig中的数组成员的更多信息,请查看this article from knpuniversity

© www.soinside.com 2019 - 2024. All rights reserved.