How to use steering wheel # as an assistant with a YAML front

I use assemble.io to automate the development of my interface and want to use the front YAML task to create a simple navigation menu.

The HTML I want to achieve is:

<li><a href="#link1">Link1</a></li> <li><a href="#link2">Link2</a></li> 

I think the correct rudder layout is this:

  {{#each sublinks}} <li><a href="#{{section}}">{{section}}</li> {{/each}} 

But what is the right YFM? I started with this, but I know that the syntax is incorrect:

 --- sublinks: - section: link1, link2 --- 
+4
source share
2 answers

For a template like this:

 {{#each sublinks}} <li><a href="#{{section}}">{{section}}</li> {{/each}} 

You need a data structure as follows:

 sublinks = [ { section: 'link1' }, { section: 'link2' }, //... ] 

and in YAML, it will look like this:

 sublinks: - section: link1 - section: link2 

You can also use this YAML:

 sublinks: - link1 - link2 

with this template:

 {{#each sublinks}} <li><a href="#{{.}}">{{.}}</li> {{/each}} 

Your YAML corresponds to a data structure like this:

 sublinks = [ { section: 'link1, link2' } ] 

and this is not very useful if you do not want to split the string 'link1, link2' using the Handlebars helper.

+9
source

By adding an excellent answer to @mu, you can also do it like this:

Given this question before YAML:

 --- sublinks: - href: link/to/foo text: Foo Text - href: link/to/bar text: Bar Text - href: link/to/baz text: Baz Text --- 

Your templates will look like this:

 {{#each sublinks}} <li><a href="#{{href}}">{{text}}</a></li> {{/each}} 

Note that the YAML specification also allows you to use a syntax more similar to JavaScript:

 --- sublinks: - {href: link/to/foo, text: Foo Text} - {href: link/to/bar, text: Bar Text} - {href: link/to/baz, text: Baz Text} --- 
+3
source

Source: https://habr.com/ru/post/1500051/


All Articles