If statements not working for value comparison

Solved

If statements not working for value comparison

Hyudryu
Shopify Partner
8 0 1

Hey everyone

 

I want to apply some custom boolean logic for my product-grid using a custom metafield.

The metafield named "type" (product.metafields.custom.type) is a single line text. When printing out the value, this is what is printed out:

 

product.metafields.custom.type: ["SPD"]

product.metafields.custom.type.value: SPD

product.metafields.custom.type.type: list.single_line_text_field

product.metafields.custom.type.list?: true

 

When writing an if statement, when using the product.metafields.custom.type.value variable, it is not entering the statement

 

 

 

 

             {%- if product.metafields.custom.type.value == 'SPD' %}
                SPD Metafield Found
              {%- endif -%}

 

 

 

 

Is there something special with liquid that I'm missing? Does the .value operator not return the literal string? Thanks!

Accepted Solution (1)

Javitoo
Shopify Partner
28 5 5

This is an accepted solution.

Try with:

{%- if product.metafields.custom.type contains "SPD" %}
    SPD Metafield Found
{%- endif -%}

 

If this helped you, Likes and Accept as Solution are highly appreciated!
Contact me at javiermizarevalo@gmail.com for custom development help 
Like my help? Buy me a coffee

View solution in original post

Reply 1 (1)

Javitoo
Shopify Partner
28 5 5

This is an accepted solution.

Try with:

{%- if product.metafields.custom.type contains "SPD" %}
    SPD Metafield Found
{%- endif -%}

 

If this helped you, Likes and Accept as Solution are highly appreciated!
Contact me at javiermizarevalo@gmail.com for custom development help 
Like my help? Buy me a coffee