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
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
I have tried using for subitem in item
and other options - but I can't get it to work - any ideas?
A YAML frontmatter is a series of meta variables that can be defined to describe information of the file that normally is not part of the text contents themselves, such as authors, keywords, and the title.
Front matter tells Jekyll to parse a file. You add predefined variables, which are YAML sets, to the front matter. Then, you can use Liquid tags in your files to access the front matter. Front matter is indicated with two triple-dashed lines.
The Front Matter extension tries to make it easy to manage your Markdown pages/content. Within a Markdown page, we allow you to fold the file's Front Matter to be less distracting when writing. Also, do we highlight the Front Matter content to create a visual difference between content and metadata.
Aliases. front matter. YAML, also known as front matter, is designed to be file-level metadata that is readable by humans and Obsidian. Front matter is a section of plain text attributes that starts at the first line of the file.
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>
Produces this:
<!-- 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With