Split Description into Three Sections

Hi all,

Im trying to have 3 sections on my product description. What's the best solution for this? I usually use:

{{ product.description | split: '<!-- split -->' | first }}
{{ product.description | split: '<!-- split -->' | last }}


But that only seems to work for 2 sections. Anyone?


Thanks

 

0 Likes
Shopify Expert
9807 92 1561

Hey Matt,

By using split you'll create an array so you can call each item by their index. For example:

{% assign foo = 'a,b,c' | split:',' %}
1: {{ foo[0] }}
2: {{ foo[1] }}
3: {{ foo[2] }}

You'll want to add some conditional logic to make sure each section isn't blank (or false) before use.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like
Tourist
19 0 1

Hi Jason,

To create conditional logic would you use for loop or if statment?  How would it look like in this case? 

I can't figure it out :)

 

Cheers

 

 

1 Like
Excursionist
18 0 1

Hi @Jason - the super veteran of the forum!

After posting about a similar issue (slightly more complex) I found your solution here about looping through it.

However, I struggled to implement it at all and I'm not sure if this solution actually applies.

 

https://community.shopify.com/c/Technical-Q-A/Split-Product-Description-into-X-parts-tricky-one/td-p...

 

In case, you have an idea I would really appreciate your input! Thanks in advance!

 

Best,
Moritz

0 Likes