Hugo 嵌套循环迭代多级 YAML

Ben*_*zay 6 yaml hugo

我有多个级别的页面正面内容。我的页面首页看起来像这样:

grids:
- template: section
  background_image: "/uploads/2018/05/01/q-mark.png"
  rows:
  - template: row
    stack-columns: tablet-s
    cols:
    - template: column
      title: "Column-1 Title"
- template: section
  background_image: "/uploads/2018/05/01/lk.png"
  rows:
  - template: row
    stack-columns: tablet-s
    cols:
    - template: column
      title: "Column-2 Title"
    rows:
  - template: row
    stack-columns: tablet-l
    cols:
    - template: column
      title: "Column-3 Title"
Run Code Online (Sandbox Code Playgroud)

我可以显示两个网格的第一级模板名称:

{{ range .Params.grids }}
   {{ .template }}
{{ end }}
Run Code Online (Sandbox Code Playgroud)

如何返回循环内行和列的模板名称?

Ben*_*zay 6

我想到了。您可以使用嵌套范围来访问多个级别的参数:

    {{ range .Params.grids }}

      <p>Grid template name: {{ .template }}</p>

        {{ range .rows }}

          <p><strong>row template name: </strong>{{ .template }}</p>

          {{ range .cols }}

            <p><em>col template name:</em> {{ .template }}</p>

          {{ end }}

        {{ end }}

    {{ end }}
Run Code Online (Sandbox Code Playgroud)

这显示:

网格模板名称:部分

行模板名称:

列模板名称:

网格模板名称:部分

行模板名称:

列模板名称: