Split Description into Three Sections

Highlighted
Shopify Expert
26 0 3

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
9350 0 1229

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