Dimitrios Markopoulos
Dimitrios Markopoulos

Reputation: 393

Access an array inside an array in Twig

I have an array of the following form with many items. How can I get the values of the "data" key in Twig?

array(4) {
["schema"]=>
  string(20) "decision_public.json"
  ["data"]=>
  array(10) {
    [0]=>
    array(8) {
      ["id"]=>
      string(23) "looks_bad_account_abuse"
      ["name"]=>
      string(9) "Looks Bad"
}

I tried for inside a for, but I cant get the data.

Upvotes: 1

Views: 691

Answers (1)

Dimitrios Markopoulos
Dimitrios Markopoulos

Reputation: 393

@DarkBee you gave me an idea here is the solution:

{% for key, decision in decisions %}
        {% if key=='data' %}
        {% for item in decisions['data'] %}
         <option>{{item.id}}</option>
         {% endfor %}
        {% endif %}
    {% endfor %}

Upvotes: 2

Related Questions