Search code examples
symfonytwigyamlgrav

Twig & Yaml with Grav


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


Solution

  • 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 %}