SilverWebBuzz

 Join Silver Webbuzz at GITEX Global 2023 – The Year to Imagine AI in Everything. Meet us.

Shopify Liquid Does Not Contain

Shopify Liquid Does Not Contain
Get in Touch With Us
Submitting the form below will ensure a prompt response from us.

    In Liquid (Shopify’s templating language), to check if a string, array, or object does not contain something, you use contains combined with a not or a negation (unless block or !). 0

    Basic "does not contain" in Shopify Liquid

    Here are the common ways:

    1. Using unless with contains:

    liquid

    {% unless product.title contains ‘Sneakers’ %}
         <!– This product title does NOT contain “Sneakers” –>
        <p>This is not a sneaker product.</p>
    {% endunless %}

    2. Using if and not :

    liquid

    {% if product.title contains ‘Sneakers’ %}
         <p>This is a sneaker product.</p>
    {% else %}
         <p>This is not a sneaker product.</p>
    {% endif %}

    3. Negation using ! (only supported in certain Shopify environments):

    liquid

    {% if !(product.title contains ‘Sneakers’) %}
         <p>This is not a sneaker product.</p>
    {% endif %}

    (But ! is less common in Liquid; usually unless is safer.)

    Example: Checking Tags

    If you want to check if a product does not have a certain tag:

    liquid

    {% unless product.tags contains ‘Summer’ %}
         <p>This is not a summer collection item.</p>
    {% endunless %}

    Quick Tip:

    • contains
      is case-sensitive. “sneakers” and “Sneakers” are different.
    • Always lowercase both sides if needed:

    liquid

    {% unless product.title | downcase contains ‘sneakers’ %}

    About Author

    Bhavik Koradiya is the CEO / Co. Founder of Silver WebBuzz Pvt. Ltd. Having 18+ years Experience in LAMP technology. I have expert in Magento, Joomla, WordPress, Opencart, e-commerce and many other open source. Specialties: Magento, WordPress, OpenCart, Joomla, JQuery, Any Open source.

    Scroll to Top