Подтвердить что ты не робот

Передняя панель YAML для Jekyll и вложенные списки

У меня есть набор вложенных списков ямлов с чем-то вроде следующего:

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, и я могу использовать логический оператор для определения наличия вложенных продуктов - то, что я НЕ МОЖЕТ сделать, - это цикл через несколько nested-products за итерацию top-level

Я пробовал использовать for subitem in item и другие параметры - но я не могу заставить его работать - любые идеи?

4b9b3361

Ответ 1

Update

В этом примере я просто написал (называемый 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 nested 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 nested associate value</li>
    </ul>
  </li>
  <li>Product Three: Value</li>
  <li>Product Four: SomeValue</li>
</ul>

<p>Hope that answers it</p>

</body>
</html>