Liquid, JavaScript, themes, sales channels
Is there way to hide existing section when metaobject definition used. I have large product catalog and instead of creating different product templates, looking for the way where easy to apply some edits to code section file to display dynamic content if section exists with metaobject definition.
Example before/after section used as metaobject with many different fields and want to display section only when metaobject definition exists else want to hide it.
Thanks.
Hey.
You can use this code:
{% if product.metafields.custom.yourMetafieldName.value != blank %}
// Your Section
{%- endif %}
This will make code in the if-statement only appear if the metafield is not empty.
Please note that you need to edit the theme in the right place to make this change work.
Greetings
It is for metafield definition. Looking for metaobject as there are multiple fields included in it.
Hey.
I see. Sorry for the confusion.
You can use this code:
{% if product.metafields.custom.yourMetaObject %}
// Your section
{%- endif %}
To make this work, you first have to create a metaobject in content → metaobjects. After that, you have to assign the metaobject as a product metafield.
With the code I mentioned above, the section will show up when your product has a metaobject assigned.
Having a similar issue in an Image with Text section, and I just can't figure out where to place the "if" code mentioned above so that this section will not appear on my page when there are no values in these metafields.
"0c50a836-5c60-4c74-9a03-a4f198b3f2f0": {
"type": "image-with-text",
"blocks": {
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-heading-1": {
"type": "heading",
"settings": {
"heading": "{{ metaobject.event_title.value }}",
"heading_size": "h2"
}
},
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-text-1": {
"type": "text",
"settings": {
"text": "<p>{{ metaobject.event_date_and_time | metafield_tag }}<\/p>",
"text_style": "body"
}
},
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-button-1": {
"type": "button",
"disabled": true,
"settings": {
"button_label": "Button label",
"button_link": "",
"button_style_secondary": false
}
}
User | RANK |
---|---|
38 | |
28 | |
13 | |
13 | |
10 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023