How to show or hide content from a block inside a section in liquid

How to show or hide content from a block inside a section in liquid

charliehenry
Shopify Partner
12 0 1

Hello there,

I want to be able to hide/or show an object, depending on "if" the meta field is empty or not, of an image/icon, on the schema structure it is a "block" coming from a "section".

So if the block content is not filled, is not shown.

 

I'm able to hide and show content if the checkbox from the section by using

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

But when I try the same for a block, for example 

.content_tooltip

seems not been working

 

Any help is much appreciated

 

Structure on store front:

Screenshot 2023-10-05 at 15.15.53.png

 

{% stylesheet %}
{% endstylesheet %}

{% javascript %}
{% endjavascript %}




{%- if blocks.settings.content_tooltip != blank -%}  
  
  <div class="flex-tooltip_main">
  <p> Hello </p>
  </div>


{%- endif -%}




{% schema %}
{
  "name": "Tools Tips",
  "tag": "section",
  "class": "slideshow",
  "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 3 insights per product."
          },
    {
      "type": "text",
      "id": "title",
      "label": "Tool Tips"
    },
    {
          "type": "color",
          "id": "icon_bg_color",
          "label": "Icons Background",
          "default":"#ffffff"
          },
          {
          "type": "color",
          "id": "tooltip_bg_color",
          "label": "Tool Tips Background",
          "default":"#ffffff"
          },
          {
          "type": "color",
          "id": "Text_tooltip_color",
          "label": "Tool Tips Text",
          "default":"#ffffff"
          }
          
  ],
  "max_blocks": 3,
  "blocks": [
     {
       "name": "Tool",
       "type": "slide",
       "settings": [
         
          {
          "type": "richtext",
          "id": "content_tooltip",
          "label": "Content One (1)"
          },
         {
          "type": "image_picker",
          "id": "tooltip_icon",
          "label": "Icon ToolTip",
          "info": "Recommended .svg format"
          }
       ]
     }
  ],
  "presets": [
    {
      "name": "Tools Tips",
      "settings": {
        "title": "Tool Tips"
      },
      "blocks": [
        {
          "type": "slide"
        },
        {
          "type": "slide"
        }
      ]
    }
  ],
  "locales": {
    "en": {
      "title": "Tool Tips"
    },
    "fr": {
      "title": "Tool Tips"
    }
  },
  "enabled_on": {
    "templates": ["*"],
    "groups": ["footer"],
    "groups": ["aside"]
  }
}
{% endschema %}

Thank you!

Reply 1 (1)

erik_lindberg_s
Shopify Partner
19 3 6

Hi 

 

To access the blocks you will need to loop through them. 

{%- for block in section.blocks -%}

{%- endfor -%}

 This is not the case for 

section.settings