Conditional liquid code not working

Conditional liquid code not working

miltokas
Explorer
106 0 32

Hi all!

I have a simple if condition that if a metafield has a page select it shows a chat size link. This works fine.

Then I added a condition to do the same for another metafield and suddenly it show both duplicated.

Example of page with duplicated links: https://venga-store.com/products/champagne-metallic-sequin-dress

And in this other case, only the Chart Size page is set and the page displays both links: https://venga-store.com/collections/mens-festival-outfits/products/leather-vest-t-shirt

 

            {%- when 'popup' -%}
              {% comment %} MGO: Show Chart Table if not empty {% endcomment %}            
              {%- if product.metafields.custom.size_chart != blank -%}
                <modal-opener
                  class="product-popup-modal__opener no-js-hidden quick-add-hidden"
                  data-modal="#PopupModal-{{ block.id }}"
                  {{ block.shopify_attributes }}>
  
                 <svg class="icon icon-accordion" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 20 20"><path d="M18.9836 5.32852L14.6715 1.01638L1.01638 14.6715L5.32852 18.9836L18.9836 5.32852ZM15.3902 0.297691C14.9933 -0.0992303 14.3497 -0.0992303 13.9528 0.297691L0.297691 13.9528C-0.0992301 14.3497 -0.0992305 14.9932 0.297691 15.3902L4.60983 19.7023C5.00675 20.0992 5.65029 20.0992 6.04721 19.7023L19.7023 6.04721C20.0992 5.65029 20.0992 5.00675 19.7023 4.60983L15.3902 0.297691Z" fill-rule="evenodd"></path>
                      <path d="M11.7863 2.67056C11.9848 2.4721 12.3065 2.4721 12.505 2.67056L14.4237 4.58927C14.6222 4.78774 14.6222 5.1095 14.4237 5.30796C14.2252 5.50642 13.9035 5.50642 13.705 5.30796L11.7863 3.38925C11.5878 3.19079 11.5878 2.86902 11.7863 2.67056Z"></path>
                      <path d="M8.93891 5.36331C9.13737 5.16485 9.45914 5.16485 9.6576 5.36331L11.5763 7.28202C11.7748 7.48048 11.7748 7.80225 11.5763 8.00071C11.3779 8.19917 11.0561 8.19917 10.8576 8.00071L8.93891 6.082C8.74045 5.88354 8.74045 5.56177 8.93891 5.36331Z"></path>
                      <path d="M6.24307 8.20742C6.44153 8.00896 6.76329 8.00896 6.96175 8.20742L8.88047 10.1261C9.07893 10.3246 9.07893 10.6464 8.88047 10.8448C8.68201 11.0433 8.36024 11.0433 8.16178 10.8448L6.24307 8.92611C6.0446 8.72765 6.0446 8.40588 6.24307 8.20742Z"></path>
                      <path d="M3.37296 10.8776C3.57142 10.6791 3.89319 10.6791 4.09165 10.8776L6.01036 12.7963C6.20882 12.9948 6.20882 13.3165 6.01036 13.515C5.8119 13.7134 5.49013 13.7134 5.29167 13.515L3.37296 11.5963C3.1745 11.3978 3.1745 11.076 3.37296 10.8776Z"></path></svg>                   
                                       
                  <button
                    id="ProductPopup-{{ block.id }}"
                    class="product-popup-modal__button link"
                    type="button"
                    aria-haspopup="dialog"
                  >        
                    {{ block.settings.text | default: block.settings.page.title }}
                  </button>                               
                </modal-opener>
                              
                <a href="{{ block.settings.page.url }}" class="product-popup-modal__button link no-js">
                  {{- block.settings.text -}}
                </a>
            {%- endif -%}


           {%- when 'popup' -%}
              {% comment %} MGO: Show Non-Refundable if not empty {% endcomment %}            
              {%- if product.metafields.custom._handmade_and_custom_made_to_order != blank -%}
                <modal-opener
                  class="product-popup-modal__opener no-js-hidden quick-add-hidden"
                  data-modal="#PopupModal-{{ block.id }}"
                  {{ block.shopify_attributes }}>
  
                 <svg class="icon icon-accordion" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 20 20"><path d="M18.9836 5.32852L14.6715 1.01638L1.01638 14.6715L5.32852 18.9836L18.9836 5.32852ZM15.3902 0.297691C14.9933 -0.0992303 14.3497 -0.0992303 13.9528 0.297691L0.297691 13.9528C-0.0992301 14.3497 -0.0992305 14.9932 0.297691 15.3902L4.60983 19.7023C5.00675 20.0992 5.65029 20.0992 6.04721 19.7023L19.7023 6.04721C20.0992 5.65029 20.0992 5.00675 19.7023 4.60983L15.3902 0.297691Z" fill-rule="evenodd"></path>
                      <path d="M11.7863 2.67056C11.9848 2.4721 12.3065 2.4721 12.505 2.67056L14.4237 4.58927C14.6222 4.78774 14.6222 5.1095 14.4237 5.30796C14.2252 5.50642 13.9035 5.50642 13.705 5.30796L11.7863 3.38925C11.5878 3.19079 11.5878 2.86902 11.7863 2.67056Z"></path>
                      <path d="M8.93891 5.36331C9.13737 5.16485 9.45914 5.16485 9.6576 5.36331L11.5763 7.28202C11.7748 7.48048 11.7748 7.80225 11.5763 8.00071C11.3779 8.19917 11.0561 8.19917 10.8576 8.00071L8.93891 6.082C8.74045 5.88354 8.74045 5.56177 8.93891 5.36331Z"></path>
                      <path d="M6.24307 8.20742C6.44153 8.00896 6.76329 8.00896 6.96175 8.20742L8.88047 10.1261C9.07893 10.3246 9.07893 10.6464 8.88047 10.8448C8.68201 11.0433 8.36024 11.0433 8.16178 10.8448L6.24307 8.92611C6.0446 8.72765 6.0446 8.40588 6.24307 8.20742Z"></path>
                      <path d="M3.37296 10.8776C3.57142 10.6791 3.89319 10.6791 4.09165 10.8776L6.01036 12.7963C6.20882 12.9948 6.20882 13.3165 6.01036 13.515C5.8119 13.7134 5.49013 13.7134 5.29167 13.515L3.37296 11.5963C3.1745 11.3978 3.1745 11.076 3.37296 10.8776Z"></path></svg>                   
                                       
                  <button
                    id="ProductPopup-{{ block.id }}"
                    class="product-popup-modal__button link"
                    type="button"
                    aria-haspopup="dialog"
                  >        
                    {{ block.settings.text | default: block.settings.page.title }}
                  </button>                               
                </modal-opener>
                              
                <a href="{{ block.settings.page.url }}" class="product-popup-modal__button link no-js">
                  {{- block.settings.text -}}
                </a>
            {%- endif -%}

 

miltokas_0-1734454490257.png

 

Replies 6 (6)

zack_dev
Shopify Partner
92 15 15

try with elseif 

     {%- when 'popup' -%}
              {% comment %} MGO: Show Chart Table if not empty {% endcomment %}            
              {%- if product.metafields.custom.size_chart != blank -%}
                <modal-opener
                  class="product-popup-modal__opener no-js-hidden quick-add-hidden"
                  data-modal="#PopupModal-{{ block.id }}"
                  {{ block.shopify_attributes }}>
  
                 <svg class="icon icon-accordion" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 20 20"><path d="M18.9836 5.32852L14.6715 1.01638L1.01638 14.6715L5.32852 18.9836L18.9836 5.32852ZM15.3902 0.297691C14.9933 -0.0992303 14.3497 -0.0992303 13.9528 0.297691L0.297691 13.9528C-0.0992301 14.3497 -0.0992305 14.9932 0.297691 15.3902L4.60983 19.7023C5.00675 20.0992 5.65029 20.0992 6.04721 19.7023L19.7023 6.04721C20.0992 5.65029 20.0992 5.00675 19.7023 4.60983L15.3902 0.297691Z" fill-rule="evenodd"></path>
                      <path d="M11.7863 2.67056C11.9848 2.4721 12.3065 2.4721 12.505 2.67056L14.4237 4.58927C14.6222 4.78774 14.6222 5.1095 14.4237 5.30796C14.2252 5.50642 13.9035 5.50642 13.705 5.30796L11.7863 3.38925C11.5878 3.19079 11.5878 2.86902 11.7863 2.67056Z"></path>
                      <path d="M8.93891 5.36331C9.13737 5.16485 9.45914 5.16485 9.6576 5.36331L11.5763 7.28202C11.7748 7.48048 11.7748 7.80225 11.5763 8.00071C11.3779 8.19917 11.0561 8.19917 10.8576 8.00071L8.93891 6.082C8.74045 5.88354 8.74045 5.56177 8.93891 5.36331Z"></path>
                      <path d="M6.24307 8.20742C6.44153 8.00896 6.76329 8.00896 6.96175 8.20742L8.88047 10.1261C9.07893 10.3246 9.07893 10.6464 8.88047 10.8448C8.68201 11.0433 8.36024 11.0433 8.16178 10.8448L6.24307 8.92611C6.0446 8.72765 6.0446 8.40588 6.24307 8.20742Z"></path>
                      <path d="M3.37296 10.8776C3.57142 10.6791 3.89319 10.6791 4.09165 10.8776L6.01036 12.7963C6.20882 12.9948 6.20882 13.3165 6.01036 13.515C5.8119 13.7134 5.49013 13.7134 5.29167 13.515L3.37296 11.5963C3.1745 11.3978 3.1745 11.076 3.37296 10.8776Z"></path></svg>                   
                                       
                  <button
                    id="ProductPopup-{{ block.id }}"
                    class="product-popup-modal__button link"
                    type="button"
                    aria-haspopup="dialog"
                  >        
                    {{ block.settings.text | default: block.settings.page.title }}
                  </button>                               
                </modal-opener>
                              
                <a href="{{ block.settings.page.url }}" class="product-popup-modal__button link no-js">
                  {{- block.settings.text -}}
                </a>


             {%- elsif product.metafields.custom._handmade_and_custom_made_to_order != blank -%}
                <modal-opener
                  class="product-popup-modal__opener no-js-hidden quick-add-hidden"
                  data-modal="#PopupModal-{{ block.id }}"
                  {{ block.shopify_attributes }}>
  
                 <svg class="icon icon-accordion" aria-hidden="true" focusable="false" xmlns="http://www.w3.org/2000/svg" width="15" height="15" viewBox="0 0 20 20"><path d="M18.9836 5.32852L14.6715 1.01638L1.01638 14.6715L5.32852 18.9836L18.9836 5.32852ZM15.3902 0.297691C14.9933 -0.0992303 14.3497 -0.0992303 13.9528 0.297691L0.297691 13.9528C-0.0992301 14.3497 -0.0992305 14.9932 0.297691 15.3902L4.60983 19.7023C5.00675 20.0992 5.65029 20.0992 6.04721 19.7023L19.7023 6.04721C20.0992 5.65029 20.0992 5.00675 19.7023 4.60983L15.3902 0.297691Z" fill-rule="evenodd"></path>
                      <path d="M11.7863 2.67056C11.9848 2.4721 12.3065 2.4721 12.505 2.67056L14.4237 4.58927C14.6222 4.78774 14.6222 5.1095 14.4237 5.30796C14.2252 5.50642 13.9035 5.50642 13.705 5.30796L11.7863 3.38925C11.5878 3.19079 11.5878 2.86902 11.7863 2.67056Z"></path>
                      <path d="M8.93891 5.36331C9.13737 5.16485 9.45914 5.16485 9.6576 5.36331L11.5763 7.28202C11.7748 7.48048 11.7748 7.80225 11.5763 8.00071C11.3779 8.19917 11.0561 8.19917 10.8576 8.00071L8.93891 6.082C8.74045 5.88354 8.74045 5.56177 8.93891 5.36331Z"></path>
                      <path d="M6.24307 8.20742C6.44153 8.00896 6.76329 8.00896 6.96175 8.20742L8.88047 10.1261C9.07893 10.3246 9.07893 10.6464 8.88047 10.8448C8.68201 11.0433 8.36024 11.0433 8.16178 10.8448L6.24307 8.92611C6.0446 8.72765 6.0446 8.40588 6.24307 8.20742Z"></path>
                      <path d="M3.37296 10.8776C3.57142 10.6791 3.89319 10.6791 4.09165 10.8776L6.01036 12.7963C6.20882 12.9948 6.20882 13.3165 6.01036 13.515C5.8119 13.7134 5.49013 13.7134 5.29167 13.515L3.37296 11.5963C3.1745 11.3978 3.1745 11.076 3.37296 10.8776Z"></path></svg>                   
                                       
                  <button
                    id="ProductPopup-{{ block.id }}"
                    class="product-popup-modal__button link"
                    type="button"
                    aria-haspopup="dialog"
                  >        
                    {{ block.settings.text | default: block.settings.page.title }}
                  </button>                               
                </modal-opener>
                              
                <a href="{{ block.settings.page.url }}" class="product-popup-modal__button link no-js">
                  {{- block.settings.text -}}
                </a>
            {%- endif -%}


- Helpful? Like or Accept solution, - Buy me Coffee


-

Contact me

miltokas
Explorer
106 0 32

Hi @zack_dev , thanks a lot for your help!

That fixed the issue with the duplicated text with link but the other corner case still occurs. 

Meaning, now for all products for which the first condition is true (Chart Size table) it also displays the Non-Returnable item link even tough the condition is not true.

Honestly I don't get why it goes inside that condition, the Metafield is empty. 

miltokas
Explorer
106 0 32
zack_dev
Shopify Partner
92 15 15

it can be that the metafield is not blank you can call the metafield seperately to check what is its value .



- Helpful? Like or Accept solution, - Buy me Coffee


-

Contact me

miltokas
Explorer
106 0 32

I printed both values and they are the same, even tough the second one should be empty.

{{ product.metafields.custom.size_chart }}
{{ product.metafields.custom.made_to_order }}

miltokas_0-1734535837417.png

 

How can this be, one of the value should be empty as I didn't fill the metafield.

 

zack_dev
Shopify Partner
92 15 15

not sure  😁

try to check the metafields entries if its empty try to fill it and then again remove it or make a new metafield entry to test.



- Helpful? Like or Accept solution, - Buy me Coffee


-

Contact me