Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll/Liquid - how to add large blocks of text to YAML front matter?

I'm trying to implement a service catalog in Jekyll, in which each of 20 or 30 pages will contain a 7x2 table. The left column will hold labels, e.g. Overview, Available To, etc, while the right column will hold between one line and several paragraphs of text. I was hoping to characterize the right column with Liquid variables, e.g. {overview}, {availableTo}

I've noticed that the YAML seems to be very picky about line breaks, and accordingly I've had to input these paragraphs and their markup on one line which can go on for several screen-widths. This is a problem because it's annoying, and also because I'd like these front-matters to be editable by technical but non-webdev users. Is there a way to have the front matter tolerate breaks?

Alternatively, is there a way that I could populate this table with the {content} section, without having to recode the table into it each time?

like image 656
patrickjmc Avatar asked Jul 18 '11 15:07

patrickjmc


People also ask

How do I add YAML front matter?

YAML frontmatters can be defined at the beginning of a file, by starting on the first line with three dashes ( --- ) and ending the frontmatter either with three dashes or three dots (the former variant is more common). They contain valid YAML and can be used to define arbitrary variables.

What is front matter Jekyll?

Front matter is a snippet of YAML placed between two triple-dashed lines at the start of a file. You can use front matter to set variables for the page: --- my_number: 5 --- You can call front matter variables in Liquid using the page variable.

What is front matter Markdown?

Frontmatter is a way to identify metadata in Markdown files. Metadata can literally be anything you want it to be, but often it's used for data elements your page needs and you don't want to show directly. Some examples of common metadata are: Title of the post. Description for SEO purposes.


1 Answers

Yaml syntax for multi-line strings is this one:

body: |   This is a multi-line string.   "special" metacharacters may   appear here. The extent of this string is   indicated by indentation.  

Notice that the first line must be an space followed by the | character and a new line. Then you must indent the text one level more than its parent.

Consequently, you can create one item this way:

item1:   overview: |     overview text     more overview text   available_to: 2012-01-01   foo: |     foo text     more foo text 

It seems to me that you also want to arrange your items in order. You can employ a yaml list for that:

catalog:   - id: item 1     overview: |       overview text       more overview text     available_to: 2012-01-01     foo: |       foo text       more foo text     ...   - id: item2     overview: <similar to above> 

I hope this helps!

like image 163
kikito Avatar answered Sep 21 '22 15:09

kikito