【问题标题】:Dynamic lists from Jekyll YAML arraysJekyll YAML 数组中的动态列表
【发布时间】:2020-06-13 16:24:49
【问题描述】:

我有一个产品列表,每个产品都有一个嵌套 yaml 列表的功能列表

- product: Product n1
  features:
  - feature1
  - feature2
  - feature3

- product: Product n2
  features:
  - feature1
  - feature2

- product: Product n3
  features:
  - feature1
  - feature2
  - feature3
  - feature4
  - feature5

目标:创建一个 div 列表,每个产品一个,带有标题和功能列表。

我尝试使用 for subitem in item,但无法使用 - 有什么想法吗?

【问题讨论】:

    标签: yaml jekyll


    【解决方案1】:

    我用下面的代码解决了这个问题:

    {% for product in site.data.products %}
    
      <div>
    
        <h2>{{ product.product }}</h2>
    
        <ul>
    
          {% for feature in product.features %}
            <li>{{ feature }}</li>
          {% endfor %}
    
        </ul>
    
      </div>
    
    {% endfor %}
    
    

    【讨论】:

      猜你喜欢
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-24
      • 1970-01-01
      相关资源
      最近更新 更多