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

3
  • 1
    Possible duplicate of How can I access an array/object? Commented Aug 31, 2018 at 12:34
  • @Loek I am asking that how to render a value from array,like states.vars.choices.option 35 Commented Aug 31, 2018 at 12:38
  • The same way you render anything in Symfony? return $this->render('my-template', ['variable' => $variable])? Commented Aug 31, 2018 at 12:39

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.