简体   繁体   English

树枝和Yaml与Grav

[英]Twig & Yaml with Grav

I am currently creating a module on Grav but I have a problem. 我目前正在Grav上创建模块,但是有问题。 Yaml : 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 标题正确显示

Because Table is an array of object 因为Table是一个对象数组

https://twigfiddle.com/jbde9m 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 %}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM