Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
In image-with-text.liquid I have the following if statement to hide collapsible rows if value of first metafield is empty: {%- if product.metafields.my_fields.collabsible_1_heading.value != blank -%}
This works perfectly, however I only want this rule to apply on product templates so tried modifying the rule to this:
{%- if template == "product" and product.metafields.my_fields.collabsible_1_heading.value != blank -%}
But that doesn't seem to work.
also tried:
- {%- unless template == "page" -%}
- {%- if template contains "product" and product.metafields.my_fields.collabsible_1_heading.value != blank -%}
full code section:
{%- unless template == "page" -%}
{%- if product.metafields.my_fields.collabsible_1_heading.value != blank -%}
<div class="grid__item" style="width: 100%;">
{%- for block in section.blocks -%}
{%- if block.type == 'collapsible_row' -%}
<div class="accordion{% if section.settings.layout == 'row' %} content-container color-{{ section.settings.container_color_scheme }} gradient{% endif %}" {{ block.shopify_attributes }}>
<details id="Details-{{ block.id }}-{{ section.id }}"{% if section.settings.open_first_collapsible_row and forloop.first %} open{% endif %}>
<summary id="Summary-{{ block.id }}-{{ section.id }}">
<h3 class="accordion__title h4">
{{ block.settings.heading }}
</h3>
{% render 'icon-caret' %}
</summary>
<div class="accordion__content rte" id="CollapsibleAccordion-{{ block.id }}-{{ section.id }}" role="region" aria-labelledby="Summary-{{ block.id }}-{{ section.id }}">
{{ block.settings.row_content }}
{{ block.settings.page.content }}
</div>
</details>
</div>
{%- endif -%}
{%- endfor -%}
</div>
{%- endif -%}
{%- endunless -%}
Would be extremely glad if someone has a fix to this.
Solved! Go to the solution
This is an accepted solution.
So I found the fix myself:
First have the section to show on product templates with the no-display metafield rule:
{%- if template contains 'product' and product.metafields.my_fields.collabsible_1_heading.value != blank -%}
Then create new if statement to show on page templates without the no-display metafield rule:
{%- if template contains 'page' -%}
Have you tried like this, check first for the template and then the metafield:
{%- if template == "product" -%}
{%- if product.metafields.my_fields.collabsible_1_heading.value != blank -%}
{%- endif -%}
{%- endif -%}
Thank you, but also doesn't do the trick...
This is an accepted solution.
So I found the fix myself:
First have the section to show on product templates with the no-display metafield rule:
{%- if template contains 'product' and product.metafields.my_fields.collabsible_1_heading.value != blank -%}
Then create new if statement to show on page templates without the no-display metafield rule:
{%- if template contains 'page' -%}
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