yaml - Hugo 嵌套循环遍历多级 YAML

标签 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"

我可以为我的两个网格显示一级模板名称:
{{ range .Params.grids }}
   {{ .template }}
{{ end }}

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

最佳答案

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

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

这显示:

网格模板名称:节

行模板名称:

col 模板名称: column

网格模板名称:节

行模板名称:

col 模板名称: column

关于yaml - Hugo 嵌套循环遍历多级 YAML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51003102/

相关文章:

r - 使用 blogdown 时,如何从学术 Hugo 主题的主页中删除学术和演示部分?

hugo - 订购菜单项

javascript - 如何在 Rails 应用程序中通过 javascript 引用 yaml 文件中的字符串?

java - 使用 Spring Boot 将 YAML 属性绑定(bind)到 Map<String, List<String>> 类型

documentation - 记录 yaml

java - 具有以下架构的类的 .yaml 结构应该是什么

amazon-s3 - 如何修复 AWS CloudFormation 中的 "Unable to validate the following destination configurations"?

r - 使用 blogdown 后 Hugo 不读取 .Rmd 文件

雨果没有从正面渲染摘要

hugo - 如何为 Hugo 中的“关于”页面设置不同的 frontmatter?