Accessing _data in Jekyll (loop in loop)

后端 未结 1 1800
春和景丽
春和景丽 2021-01-18 11:57

Given this YAML:

- maincategory:
    title: \"Projects\"
    subcategory:
        title: \"General\"
        item:
          title: \"Alpha\"
        item:
          


        
1条回答
  •  醉梦人生
    2021-01-18 12:08

    YAML:

    - title: "Projects"
      subcategories:
        - title: "project-sub1"
          items:
            - title: "project-sub1-item1"
              href: "#"
            - title: "project-sub1-item2"
              href: "#"
        - title: "project-sub2"
          items:
            - title: "project-sub2-item1"
              href: "#"
            - title: "project-sub2-item2"
              href: "#"
    
    - title: "Support"
      subcategories:
       - title: "support-sub1"
         items:
          - title: "support-sub1-item1"
            href: "#"
          - title: "support-sub1-item2"
            href: "#"
    

    Nested loops:

    {% for entry in site.data.entries %}
      

    {{ entry.title }}

    {% for subcategory in entry.subcategories %}

    {{ subcategory.title }}

    {% endfor %} {% endfor %}

    Output:

    Projects

    project-sub1

    project-sub2

    Support

    support-sub1

    0 讨论(0)
提交回复
热议问题