I’m looking to hide content if the metafields are empty for a product, but right now it’s returning it for all pages which means my if statement is broken somewhere.
Product Page
{% if product.metafields.review %}
{% include 'extra-review' %}
{% else %}
{% endif %}
Review Snippet Page (extra-review.liquid)
{% assign review = product.metafields.review %}
{% assign key = 'author' %}
{% assign key = 'author-img' %}
{% assign key = 'long' %}
<p> Hello world </p>
Any help would be brilliant
EDIT
Added review metafields layout
2
Answers
Truthiness in Liquid is not like Javascript. I’ve been bitten by this a few times:
Your test should be:
and
review
inproduct.metafields.review
is the namespace of the review metafields. see https://help.shopify.com/themes/liquid/objects/metafieldTo check if a namespace exists you can do a comparison against
blank
. For example:You could also used the
size
if you wanted to ensure you had three keys. Here we simply output the size:More info on truthy/falsy can be found in the Shopify docs:
https://help.shopify.com/themes/liquid/basics/true-and-false