Shopify themes, liquid, logos, and UX
Hi all, I've spent hours trying to hide metafields in *blog posts* when they are empty and I can't get anything to work.
I want to add metafields for a featured product and a featured collection at the end of my blog posts: but I want to hide them when they're not assigned. I've set up the metafields (blog-product and blog-collection).
I've watched/read several solutions and haven't gotten any to work. The following one responded, but hides ALL metafields - whether they're assigned or not:
{% if collection.metafields.custom.blog-product == blank %}
<style>
#shopify-section-template--16710703251698__featured_product_3JWUiz
{display: none;
}
</style>
{% endif %}
As you can see, I added them within the shop editor on the "blog post" settings.
Does anyone have any solutions for this? It's a handy feature, if I can get it to display only when it's populated 🙂
i suggest you to do not display none make a condition like below that if the field is empty there will be nothing to show.
{% if collection.metafields.custom.blog-product == blank %}
{% else %}
{{ collection.metafields.custom.blog-product }}
{% endif %}
OR 2nd Condition will be
{% if collection.metafields.custom.blog-product != blank %}
{{ collection.metafields.custom.blog-product }}
{% endif %}
Thanks
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024