A company that I’m doing work with has added custom tags to each of my products. The problem I’m having is trying to find a meaningful way to work with this data.
product.tags give me this.
value1:abc
value2:def
value3:ghi
value4:jkl
My problem is that each of these tags is a complete string.
I need to figure out a way to say — if value1 == "something" do "this" end —
I’ve tried seeing if I can make something happen with product.tags | JSON, but as you can imagine that doesn’t really help either. I’ve looked up working with the products API and how to achieve what I want– but it seems like there might be an easier way to achieve this.
Can anyone provide any insight?
The end result is I need to display specific copy on my product page depending on what those tags values (after the : ) are.
2
Answers
So:
Explanation: first you loop through tags to get tag string value.
Then you split tag to get an array, then you retrieve the value and use it in you conditional statement.
Similar answer to @Alice Girard, I would use
case
andwhen
instead because of the amount of tags you need to define.