Jekyll和嵌套列表的YAML前端
我有一组嵌套的yaml列表,其中包含以下内容:Jekyll和嵌套列表的YAML前端,yaml,jekyll,Yaml,Jekyll,我有一组嵌套的yaml列表,其中包含以下内容: 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: Valu
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
对于页面中的项目,我可以使用毫无问题地循环产品。产品
,我可以使用逻辑运算符确定是否存在嵌套产品-我不能做的是循环多个嵌套产品
,每次迭代顶级
我试过在item和其他选项中为子项使用,但我无法使其工作-有什么想法吗?更新
我刚刚写的这个例子(称为index.html)
---
标题:示例
产品:
-顶级:产品一
任意值
嵌套产品:
-嵌套:关联产品
子任意:关联值
-另一位同事
子任意:及其关联值
-顶层:产品二
任意值
嵌套产品:
-嵌套:嵌套产品2
子任意:两个嵌套的关联值
-顶级:产品三
任意值
-顶级:产品四
任意:SomeValue
---
{{page.title}}
产品:
{page.products%}
- {{product.top-level}}:{{product.arbitral}}{%if-product.nested-products%}
{product.nested-products%}- {{nestedproduct.nested}}:{{nestedproduct.sub-arbitral}
{%endfor%}
{%endif%} {%endfor%}
希望能回答这个问题
产生以下结果:
<!-- 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>
榜样
产品:
- 产品一:价值
- 关联产品:关联值
- 另一个关联:及其关联值
- 产品二:价值
- 嵌套产品2:两个嵌套产品的关联值
- 产品三:价值
- 产品四:有价值
希望能回答这个问题
谢谢,我最初尝试过这个方法,但它只迭代了“子项”的第一个实例。有没有想过为什么会这样?不知道。我在我的页面中做了类似的事情,效果很好。看看我的例子。如果这会产生其他结果,则说明您的设置有问题。
<!-- 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>