Ad

Shopify / Liquid Find "-" And Remove And Content Before

- 1 answer

I have some content, for example: Product Type - Colour Name (this changes but always the same format, I want to just display the "Colour Name"

It is outputted with:

{{ product.title }}

What I need to do is use the available string filters and find and remove "-" and the content before it so it just displays the part after the hyphen "-"

Does anyone have any ideas?

Ad

Answer

You can use the split filter.

{% assign words = product.title | split: ' - ' %}
{{ words[1] }}
Ad
source: stackoverflow.com
Ad