Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YAML front matter for Jekyll and nested lists

Tags:

yaml

jekyll

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?

like image 717
motleydev Avatar asked Oct 06 '12 15:10

motleydev


People also ask

What is front matter YAML?

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.

What is front matter in Jekyll?

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.

What is front matter Markdown?

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.

What is front matter Obsidian?

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.


Video Answer


1 Answers

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> 

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> 
like image 165
Rudy Velthuis Avatar answered Nov 11 '22 01:11

Rudy Velthuis