【问题标题】:Twig & Yaml with Grav带有 Grav 的 Twig 和 Yaml
【发布时间】:2018-07-02 10:58:07
【问题描述】:

我目前正在 Grav 上创建一个模块,但我遇到了问题。 Yaml:

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

树枝:

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

我无法显示“价值” 但如果我这样做:

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

标题显示正确

【问题讨论】:

    标签: symfony twig yaml grav


    【解决方案1】:

    因为 Table 是一个对象数组

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

    【讨论】:

    • 如果我有另一个标题和内容。我将如何在 html 中显示它们?
    • 通过另一个循环
    猜你喜欢
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    相关资源
    最近更新 更多