Hi all,
I’m trying to use a product metafield as a “condition” to do some formatting on collection pages. Here’s my set up:
Each product has a metafield of “product type”. The field is: metafields.custom.prod_format. This is set up as a drop down list that allows me to pick the specific type of project. Only one selection is allowed.
On collections pages, I want some additional metafields to be displayed if the prod_format = “Merchandise”. For everything else, a slightly different set of data and formatting.
Here’s my code from the card-product.liquid file
{% if card_product.metafields.custom.prod_format == “Merchandise” %}
Product Series:
{{ card_product.metafields.custom.series }}
{{ card_product.metafields.custom.series | metafield_text }} Book #
{{ card_product.metafields.custom.number_in_series }}
{{ card_product.metafields.custom.tagline }}
{% endif %}From what I can tell my issue is in how the card_product.metafields.custom.prod_format is returning because it never hits a situation where the first “if” condition is true. So, despite products having that field set correctly, it never formats those products correctly in the grid. It always formats them in the “else” condition.
When I return card_product.metafields.custom.prod_format in text I get [Merchandise] and not Merchandise, unless I use the | metafield_text tag at the end.
So I’m guessing that the If/else process is seeing [Merchandise] as the value and not Merchandise.
How do I write this so it evaluates correctly?
I’ve tried:
- {% if card_product.metafields.custom.prod_format == “Merchandise” %}
- {% if card_product.metafields.custom.prod_format == [Merchandise] %}
- {% if card_product.metafields.custom.prod_format == “[Merchandise]” %}
- {% if card_product.metafields.custom.prod_format == ‘[“Merchandise” ]’ %}
Nothing works so that the first condition is true.
Any thoughts?
Thanks in advance.
-Justin