Jekyll和嵌套列表的YAML首要问题 [英] YAML front matter for Jekyll and nested lists
本文介绍了Jekyll和嵌套列表的YAML首要问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一组嵌套的Yaml列表,内容类似于以下内容:
I have a set of nested yaml lists with something like the following:
title: the example
image: link.jpg
products:
- top-level: Product One
arbitrary: Value
nested-products:
- nested: Associated Product
sub-arbitrary: Associated Value
- top-level: Product Two
arbitrary: Value
- top-level: Product Three
arbitrary: Value
我可以使用for item in page.products
毫无问题地遍历产品,并且可以使用逻辑运算符确定嵌套产品是否存在-我不能做的是每次top-level
迭代遍历多个nested-products
I can loop through the products with no problem using for item in page.products
and I can use a logic operator to determine if nested products exist - what I CAN'T do is loop through multiple nested-products
per iteration of top-level
我已经尝试过使用for subitem in item
和其他选项-但我无法使它生效-有任何想法吗?
I have tried using for subitem in item
and other options - but I can't get it to work - any ideas?
推荐答案
更新
我刚才写的这个例子(叫做index.html)
Update
This example I just wrote (called index.html)
---
title: the example
products:
- top-level: Product One
arbitrary: Value
nested-products:
- nested: Associated Product
sub-arbitrary: Associated Value
- nested: Another associate
sub-arbitrary: with its associated value
- top-level: Product Two
arbitrary: Value
nested-products:
- nested: nested product Two
sub-arbitrary: Two's nested's associate value
- top-level: Product Three
arbitrary: Value
- top-level: Product Four
arbitrary: SomeValue
---
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>{{ page.title }}</title>
</head>
<body>
<h4>products:</h4>
<ul>{% for product in page.products %}
<li>{{ product.top-level }}: {{ product.arbitrary }}{% if product.nested-products %}
<ul>
{% for nestedproduct in product.nested-products %} <li>{{ nestedproduct.nested }}: {{ nestedproduct.sub-arbitrary }}</li>
{% endfor %}</ul>
{% endif %}</li>{% endfor %}
</ul>
<p>Hope that answers it</p>
</body>
</html>
产生这个:
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>the example</title>
</head>
<body>
<h4>products:</h4>
<ul>
<li>Product One: Value
<ul>
<li>Associated Product: Associated Value</li>
<li>Another associate: with its associated value</li>
</ul>
</li>
<li>Product Two: Value
<ul>
<li>nested product Two: Two's nested's associate value</li>
</ul>
</li>
<li>Product Three: Value</li>
<li>Product Four: SomeValue</li>
</ul>
<p>Hope that answers it</p>
</body>
</html>
这篇关于Jekyll和嵌套列表的YAML首要问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文