Solved

How to display an element by if condition liquid

charliehenry
Shopify Partner
10 0 1

I'm having some trouble understanding what I'm doing wrong, I'm trying to show and hide content if a meta field is filled or not. In this case is an image. But It seems I'm missing something important.

 

{%- if setting.tooltip_icon_one != blank -%}
<!-- Content to be displayed when the checkbox is checked -->
<p>
Content here, images, etc.
</p> {%- endif -%}

And the shema structure:

{% schema %}
  {
    "name": "Product pages",
    "class": "section-product-template",
    "blocks": [
      {
         "type": "@app"
      },
      {
        "type": "title",
        "name": "Title",
        "limit": 1,
        "settings": [
          {
            "type": "checkbox",
            "id": "heading_h1",
            "label": "Set as primary page heading",
            "info": "info",
            "default": true
          }
        ]
      },
      {
        "type": "price",
        "name": "Price",
        "limit": 1,
        "settings": [
          {
            "type": "checkbox",
            "id": "show_tax_and_shipping",
            "label": "Show tax status and shipping policy link",
            "default": false
          }
        ]
      },


      {
        "type": "product_tooltip",
        "name": "Tool Tips",
        "limit": 1,
        "settings": [
          {
            "type": "checkbox",
            "id": "maintooltip_product",
            "default": true,
            "label": "Show Tool Tips",
            "info": "The tools tips, are soft insights about the current product displayed, there is a maximum of 4 insights per product."
          },
          {
          "type": "image_picker",
          "id": "tooltip_icon_one",
          "label": "Icon ToolTip One (1)",
          "info": "Recommended .svg format"
          },

and goes all the way down...

 

On theme store front:

Screenshot 2023-10-05 at 11.50.50.png

can you help me please to understand how can show content if a meta field is filled?

I have been trying as well, with the check box .maintooltip_product when checking the box is "checked", and shows to content, but is the same.

 

Thank you.

Accepted Solution (1)
shreyhweb
Shopify Partner
630 110 112

This is an accepted solution.

Because this is the block setting. so you should use block instead of section.

 

i mean. {%- if block.settings.maintooltip_product != blank -%} 

- If You Find Our Solution Helpful Please Like And Mark As Accepted!
- Sip, savor, and support – your Coffee Tip helps us keep coding.❤️
- If You Want To Further Discussion. Then Contact - info@shreyhsoftsolutions.com

View solution in original post

Replies 6 (6)

shreyhweb
Shopify Partner
630 110 112

@charliehenry 

 

Hello,

 

Please use this 

 

{%- if section.setting.tooltip_icon_one != blank -%}
<!-- Content to be displayed when the checkbox is checked -->
<p>
Content here, images, etc.
</p> {%- endif -%}

Because this is not a theme setting its a section setting. so must add section. before the settings.

 

if our solution is helpful for you then please like the post and tap on accepted.


Thankyou 

- If You Find Our Solution Helpful Please Like And Mark As Accepted!
- Sip, savor, and support – your Coffee Tip helps us keep coding.❤️
- If You Want To Further Discussion. Then Contact - info@shreyhsoftsolutions.com
charliehenry
Shopify Partner
10 0 1

Thank you for your reply and help,

For some reason, is still without working,

I have tried creating a section directly, and it works

But on the current one, is not working.

 

{%- if section.settings.maintooltip_product != blank -%}  
  <p> content here, etc.</p>
{%- endif -%}

 

maybe should I add bloks?

{%- if section.settings.blocks.maintooltip_product != blank -%} ?

 

Thank you

shreyhweb
Shopify Partner
630 110 112

This is an accepted solution.

Because this is the block setting. so you should use block instead of section.

 

i mean. {%- if block.settings.maintooltip_product != blank -%} 

- If You Find Our Solution Helpful Please Like And Mark As Accepted!
- Sip, savor, and support – your Coffee Tip helps us keep coding.❤️
- If You Want To Further Discussion. Then Contact - info@shreyhsoftsolutions.com
charliehenry
Shopify Partner
10 0 1

@shreyhweb 

thank you so much

shreyhweb
Shopify Partner
630 110 112

our pleasure 🙂

 

Thankyou for reaching us

 

- If You Find Our Solution Helpful Please Like And Mark As Accepted!
- Sip, savor, and support – your Coffee Tip helps us keep coding.❤️
- If You Want To Further Discussion. Then Contact - info@shreyhsoftsolutions.com
charliehenry
Shopify Partner
10 0 1

To make more context, I'm trying to make it work inside the product section.

Screenshot 2023-10-05 at 13.43.08.png

On the section test I did, it works,

but in the product section, it doesn't work "if" {%- if section.settings.maintooltip_product != blank -%} when I have checked the check box.