Liquid: [String] Replace or nl2br

Shopify Partner
124 0 3
Hi, Is there anyway to replace a string in an output or, specifically, something like PHP's nl2br() function? Basically, I have an output of {{product.description | truncate: 100}} but I need to keep it on one line as it held within some javascript. Any help appreciated. Cheers Dave
0 Likes
Highlighted
Shopify Staff
Shopify Staff
2045 0 40

I just added filters which allow you to do this:

{{product.description | truncate: 100 | newlines_to_br | strip_newlines }}

http://wiki.shopify.com/FilterReference

Tobias Lütke - Shopify CEO // http://twitter.com/tobi
0 Likes
Shopify Partner
124 0 3

Absolutely superb, thanks very much!

0 Likes
Shopify Partner
124 0 3

1 other quick question on this subject, it’s working fine now apart from when I have an apostrophe in the description.

I’m using | escape but it doesn’t escape. I line is encapsulated in apostrophes, so it causes the javascript not to work.

I have javascript tooltips that activate onMouseOver, so my code is essentially:

onMouseOver="Tip('{{product.description | strip_html | truncate: 250 | escape | newlines_to_br | strip_newlines}}');"
0 Likes