Re: Can't get custom meta fields to disappear if blank

Solved

Can't get custom meta fields to disappear if blank

Not applicable

Using a theme and It has me using metafields to add product description/preorder info on my product page (see screenshots). I'm also including the code for my main-product.liquid. I've tried a few options I've seen on the forum, but none of them seem to be working for me. If someone can tell me how to hide any metafields when blank, that would super helpful!

 

Samantha_Siman_0-1719686952970.png

Samantha_Siman_1-1719686977086.png

Samantha_Siman_2-1719686996325.png

Thank you!

 

Accepted Solution (1)

WalkYourStyle
Trailblazer
450 54 69

This is an accepted solution.

One way to do this is by surrounding the parent div with an if statement like this:

 

{% if block.settings.content != blank or block.settings.page.content != blank %}
  <div class="product__accordion accordion quick-add-hidden" {{ block.shopify_attributes }}>
    <details id="Details-{{ block.id }}-{{ section.id }}">
      <summary>
        <div class="summary__title">
          {% render 'icon-accordion', icon: block.settings.icon %}
          <h2 class="h4 accordion__title inline-richtext">
            {{ block.settings.heading | default: block.settings.page.title | escape }}
          </h2>
        </div>
        {% render 'icon-caret' %}
      </summary>
      <div class="accordion__content rte" id="ProductAccordion-{{ block.id }}-{{ section.id }}">
        {{ block.settings.content }}
        {{ block.settings.page.content }}
      </div>
    </details>
  </div>
{% endif %}

Hope this helps!

 

View solution in original post

Replies 2 (2)

WalkYourStyle
Trailblazer
450 54 69

This is an accepted solution.

One way to do this is by surrounding the parent div with an if statement like this:

 

{% if block.settings.content != blank or block.settings.page.content != blank %}
  <div class="product__accordion accordion quick-add-hidden" {{ block.shopify_attributes }}>
    <details id="Details-{{ block.id }}-{{ section.id }}">
      <summary>
        <div class="summary__title">
          {% render 'icon-accordion', icon: block.settings.icon %}
          <h2 class="h4 accordion__title inline-richtext">
            {{ block.settings.heading | default: block.settings.page.title | escape }}
          </h2>
        </div>
        {% render 'icon-caret' %}
      </summary>
      <div class="accordion__content rte" id="ProductAccordion-{{ block.id }}-{{ section.id }}">
        {{ block.settings.content }}
        {{ block.settings.page.content }}
      </div>
    </details>
  </div>
{% endif %}

Hope this helps!

 

Not applicable

That worked! Thank you so much!