I have in the MetaField "Color" – 3 values.
Red, Green and Blue. in Shopify.
I want to provide hints for these colors on the Product page. Since I have only created the meta field on all products and I don’t want to create a photo meta field here, I am checking to see if I can find the solution with an if query.
If The Meta-Field is with the color "RED", then show with graphic XY (A hint for this color).
But if Meta-Field is with color "Blue", then show me another graphic.
But if Meta-Field is with the color "Green", then show me another graphic.
If empty, no graphic.
Do you have any idea?
2
Answers
Upload three assets to your theme, named "red.png", "green.png" and "blue.png". If you can manage that feat, you’re cooking with gas. Now, in your Liquid, just read back to yourself those metafield "values". If you find a value in the color of "red", then using Liquid, make an image tag where the source points at the "red.png" asset you uploaded.
Obviously you can get fancier, and many people do, but that pattern is basic and should work enough to prove the point till you master other techniques.
Here’s a couple of options for you
Using a conditional I am first checking to see if the metafield has content, then checking the value for red, green, or blue, and displaying the relevant image by looping over an
if/elsif
tagThis can also be achieved using a case/when tag
If you want to check out the docs for this they’re here https://shopify.github.io/liquid/tags/control-flow/