0

I am currently creating a module on Grav but I have a problem. Yaml :

table:
    -
        title: Test
        content:
            -
                value: 'test1'
            -
                value: 'test2'
            -
                value: 'test3'

Twig :

{% for item in page.header.table.content %}
     <h1>{{item.value}}</h1>
{% endfor %} 

I can not display 'value' but if I do :

{% for item in page.header.table %}
      <h1>{{item.title}}</h1>
{% endfor %}

title is displayed correctly

Kol2gaR
  • 202
  • 2
  • 13

1 Answers1

2

Because Table is an array of object

https://twigfiddle.com/jbde9m

{% for item in page.header.table %}
     <h1>{{item.title}}</h1>
{% endfor %} 

{# you can also do for item in page.header.table.0.content #}
{% for item in (page.header.table|first).content %}
     <h1>{{item.value}}</h1>
{% endfor %}
goto
  • 7,908
  • 10
  • 48
  • 58