Personalized checkout and custom promotions with Shopify Scripts
The following will filter "Green" from "Green House":
{{ "Green House" | truncatewords: 1, "" }}
But is their a simple way to filter out only "House"? In other words, is it possible to remove the first word of a string/filter the second word? It would be nice if "truncatewords: -1" would allow you to truncate from right to left.
If I am trying to remove the first word for "Green House", "Red House", & "Blue House", then the easiest way I can think of is by using ' | remove: 'Green ' | remove: 'Red ' | remove: 'Blue' ' which doesn't seem very efficient, especially if i am using many different colors.
Any tips?
Solved! Go to the solution
This is an accepted solution.
Well as far as I got what you need here is the second word.
Why not split the word by space and always use the 2nd Index item
{% assign sentance = "Green House" | split: " " %}
{% if sentance[1] %}
{{ sentance[1] }}
{% endif %}
I haven’t tried the code on editor but that should work.
This is an accepted solution.
Well as far as I got what you need here is the second word.
Why not split the word by space and always use the 2nd Index item
{% assign sentance = "Green House" | split: " " %}
{% if sentance[1] %}
{{ sentance[1] }}
{% endif %}
I haven’t tried the code on editor but that should work.
User | RANK |
---|---|
4 | |
2 | |
2 | |
1 | |
1 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023