US English (US)
BS Bosnian

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Book a Demo
  • Product Updates
  • Contact Us
English (US)
US English (US)
BS Bosnian
  • Home
  • Customization
  • Customization Guides
  • Liquid Templating Basics

Shopify/Liquid Logic Syntax

How to control the logic flow

Written by Guilherme Arantes

Updated at August 25th, 2020, by David growhackscale

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Getting Started
    Users Accessibility New to Helpjuice? Start Here Content Management Multiple Languages/Translations & Localization Multilingual Knowledge Bases Analytics Video Tutorials
  • Customization
    Customization Guides
  • API V2
  • API V3 and Webhooks
  • Article Editor
  • Billing / Subscription
  • Authentication
  • Pricing
  • Swifty AI Chatbot
  • Swifty AI Helpbar
  • What's New
+ More

The Liquid Logical Statements are useful if you want to check some variable before displaying it or if you want to create a specific list based on another object.


If Statement

The If Statement allows you to verify the object value when needed:

{% if question.name == "Getting Started" %}
  <p>Only printed if the question name is "Getting Started".</p>
{% endif %}

If you just need to check on a value before printing a default text, you'd need to use the above example. But if you have a default text and want a different one in just a specific case, the best approach is the following one:

{% if question.name == "Getting Started" %}
  <p>Only printed if the question name is "Getting Started".</p>
{% else %}
  <p>This would be the default text, i.e when the question name differs from "Getting Started"</p>
{% endif %}

Notice that the If Statement must be rounded by "{%" and "%}". Also, it needs to be closed properly:

{% if ... %}
  ...
{% endif %}


For Statement

The For Statement allows you to loop through a list of objects. For instance, if you want to loop through the question list from the current category, you can use:

{% for question in category.questions %}
  <h2>{{ question.name }}</h2>
  <a href="{{ question.url }}">{{ question.name }}</a>
{% endfor %}

Another example:

<ul class="top_categories">
  {% for categories in roots_categories %}
    <li class="category_item">
      <a href="{{ category.url }}">{{ category.name }}</a>
    </li>
  {% endfor %}
</ul>

Notice that the For Statement must be rounded by "{%" and "%}". Also, it needs to be closed properly:

{% for ... %}
  ...
{% endfor %}


Real Liquid Example

This example is from a Standard Helpjuice Theme live on our Theme Library:

<ul class="main_navigation">

  {% for category in roots_categories %}
    <li><a href="{{ category.url }}">{{ category.name }}</a></li>

    {% if category.ordered_subcategories.size > 0 %}
      <ul class="subcategories">

        {% for subcategory in category.ordered_subcategories %}
          <li>
            <a href="{{ subcategory.url }}">{{ subcategory.name }}</a>
          </li>
        {% endfor %}

      </ul>
    {% endif %}

{% endfor %}
</ul>

Notice that you can have nested For Statements.


Liquid Filters

You can apply filters on the Liquid Statements. Every time you need to limit a loop statement or change the output of an object value, you can rely on Liquid Filters. Check the Shopify/Liquid Filter Syntax article.‍


Objects List

You can find the complete object reference at Shopify/Liquid Complete Objects Reference‍.


Advanced Shopify/Liquid Syntax

You can find more information about Logical Statements on the official Liquid documentation. The complete Shopify/Liquid documentation is located here.

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Basic Customization Reference
  • Shopify/Liquid Filter Syntax
  • Shopify/Liquid Global Objects

Copyright © 2025 - Helpjuice

Helpjuice, Inc. is a registered US Corporation, EIN # 45-2275731

Download W9
  • Help
  • Features
  • Pricing
  • About
  • Careers
  • Customers
  • Blog
  • Case Studies
  • Resources
  • Knowledge Base Examples
  • Privacy Policy
  • Terms of Service

Why is the knowledge base important?

With a knowledge base, you can allow your customers to self-help themselves, thus reducing your customer support by up to 60%. Furthermore, you can also have your team get instant answers to the questions they need without having to email themselves all using knowledge base software.

What is the purpose of a knowledge base?

The purpose of knowledge base software is to allow you to host your knowledge base/corporate wiki in one centralized 'hub'. Both your customers, and employees can now access information within seconds!

Made with from Miami, Bosnia, Morocco & Brasil

+1 (833) 387 3877 support@helpjuice.com
Expand