Multi-line product title / description in cart & summary

I’m using Snipcart with Kirby CMS. Product titles and descriptions are defined in textareas of multiple lines and output in data attributes as strings with <br> tags within, e.g. "Author Name<br>Book Title<br>"

Is there any way to split these strings by <br> into a new array and output each line separately?

I am using custom templates and have some React knowledge, happy to implement some custom Vue if this will be possible :slight_smile:

Hey @nzxh !

I’m not sure I understand what is the issue and what you are trying to achieve, but it is possible to split a string into an array. A simple solution could look like this:

const myStr = "Author Name<br>Book Title<be>";
const myArr = myStr.split('<br>').filter(i => i); // filter to remove empty string from array

If this does not solve your issue, please provide more details and I’ll be happy to try to help you :slight_smile:

Cheers!

Hey @dominic! Thanks for your reply, I managed to solve it by rendering the description and product title as <pre> elements as suggested here on Stack Overflow :muscle:

1 Like