How to split a line into a new line in Shopify?

I have a field in my settings.html where I expect the user to enter a few paragraphs separated by two newline characters. I would like to split this input line into an array of lines, each of which represents a paragraph.

I would like to do something like this:

 {% assign paragraphs = settings.intro | split: '\n' %} {% for paragraph in paragraphs %} <p> {{ paragraph }} </p> {% endfor %} 

I cannot figure out how to refer to a newline in Liquid. How can i do this? Is there any kind of work around?

+6
source share
1 answer

Try the following:

 {% assign paragraphs = settings.intro | newline_to_br | split: '<br />' %} {% for paragraph in paragraphs %}<p>{{ paragraph }}</p>{% endfor %} 
+16
source

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


All Articles