[SOLVED] Add line break in .yaml file


#1

Hello !
I searched for a solution to my problem and despite some interesting track, I wasn’t able to find a solution.

I have a .yaml file where I store the content of my page.
My goal is to display this data with line break in my .html template .

Here is an example of my .yaml file :

content : |
   This is the content I want
   to display
   on several lines.

I tried to use | operator which is supposed to output the following HTML code :

This is the content I want\nto display\non several lines

Note : I don’t see thoose \n in my chrome debugger so I don’t know if it works or not.

Then I tried to add the following shortcode :

{{ replace .Inner "\n" "<br/>" | safeHtml }}

and to add it in my .yaml file :

content : |
   {{ < myshortcode> }}
   This is the content I want
   to display
   on several lines.
  {{ < / myshortcode> }}

Do you know how I can solve my problem ?


#2

I think that this question was posted recently over here, but I don’t recall the topic.

Try searching the Forum or see this older workaround:


#3

Thanks for your answer !

I searched for a recent topic that would answer my question but I didn’t find anything. If someone has an other solution it would be good to know it.

However your workaround works perfectly, so thank you again !


#4

How about something like this:

---
title: "Multi-line description set using Org Special Block (YAML)"
description: >
  Short description
  of this post


  **bold** -- _italics_ --- ~~strikethrough~~ `monospace`


  These lines <br />
  show up with line breaks <br />
  but within the same paragraph.
tags: ["front-matter", "description", "special-block", "yaml", "multi-line"]
draft: false
---

Post content.

and then pass that description param (content in your case) through markdownify in the template.


Source: Markdown | Hugo rendered HTML

(I prefer TOML though.)