Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Multi-line strings in frontmatter?

Started by Muut Archive 11 years ago · 4 replies · 3931 views
11 years ago

I have a few items in my frontmatter which have long descriptions. I'd like to add line breaks to the descriptions instead of it being one long string. How is this done? Adding <br /> works but it's a pretty hacky way to do it.

I've been looking to the YAML way to do it (link here) and apparently it should be done like so:

TXT
description: |   
   here's a loong description    
   which spans multiple lines   

However, this doesn't work in Grav. What's the Grav way to do it?

11 years ago

To be honest i'm not sure. If it doesn't work then it's an issue with the Symfony YAML parser: https://github.com/symfony/symfony/issues/12095 (maybe this issue?)

You could try installing the PECL yaml parser, as that will automatically get used in place of the Symfony YAML parser if found.

11 years ago

Guess I'll have to try that. It might be the parser. Whenever I save the document, this...

TXT
    description: |
         here's a looong description
         which spans multiple lines
         third line here

... turns into this:

TXT
   description: "here's a looong description /nwhich spans multiple lines /nthird line here"

There's an /n appearing wherever a line break is supposed to be when the page is reloaded or saved. That must mean that the parser is to blame?

11 years ago

To clarify, what I meant was that the /n is a line break so that's correct, but the parser isn't parsing it into a new line for some reason in the front-end.

11 years ago

Hi @dimis,

I think the multiline string is working, but the problem lies on the Twig end how you print out the variable. By default web browsers are whitespace/newlines agnostic, meaning you have to convert all line breaks into their corresponding markup (here: <br>, see http://twig.sensiolabs.org/doc/filters/nl2br.html ). Thus the Twig one liner should do the job

TWIG
{{ page.header.description|nl2br }}

Best,
Sommerregen

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1349 9 years ago
Archive · by Muut Archive, 9 years ago
2 934 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2946 9 years ago
Archive · by Muut Archive, 9 years ago
3 1118 9 years ago