A.JRJ
A.JRJ

Reputation: 361

Rendering single data from an array

{{dump(states)}} this returns

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
}

I want to display state of choices-option 35.how to get single choice out of array which have 41 choices?.

Upvotes: 0

Views: 75

Answers (1)

kalehmann
kalehmann

Reputation: 5011

You can access array members in twig with the . or [] syntax.

Therefore the 35th choice of your choice array can be rendered like this in twig:

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

For further information how to access array members in twig take a look at this article from knpuniversity

Upvotes: 1

Related Questions