0

{{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?.

kalehmann
  • 4,821
  • 6
  • 26
  • 36
A.JRJ
  • 331
  • 1
  • 5
  • 16
  • 1
    Possible duplicate of [How can I access an array/object?](https://stackoverflow.com/questions/30680938/how-can-i-access-an-array-object) – Loek Aug 31 '18 at 12:34
  • @Loek I am asking that how to render a value from array,like _states.vars.choices.option 35_ – A.JRJ Aug 31 '18 at 12:38
  • The same way you render anything in Symfony? `return $this->render('my-template', ['variable' => $variable])`? – Loek Aug 31 '18 at 12:39

1 Answers1

1

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

kalehmann
  • 4,821
  • 6
  • 26
  • 36