Liquid How-to: Showing Conditional Content
Quite often there is a requirement to show different content to different users or times or dates. You can achieve this in a number of ways, several examples are given below.
Show Content According to the Current Store
You can access the current store being displayed via the current_store
tag, which allows you to display different content accordingly:
{% if current_store.code == 'dog-store' %}
<h1>The {{ current_store.name }} is the best for dogs</h1>
{% elsif current_store.code == 'cat-store' %}
<h1>The {{ current_store.name }} is the best for cats</h1>
{% endif %}
Show Content depending on the signed in Customer
You can also hide content unless a customer is logged in:
{% if current_customer %}
<p>Hi {{ current_customer.firstname }}!</p>
<p>Your email address is {{ current_customer.email }}</p>
<p>Your account name is {{ current_customer.account.name }}</p>
{% endif %}
Show Content depending on the signed in Account
You can also hide content unless a account is logged in:
{% if current_account %}
<p>Hi {{ current_account.firstname }}!</p>
<p>Your email address is {{ current_account.email }}</p>
<p>Your account name is {{ current_account.account.name }}</p>
{% endif %}
Show Content based on the Customer Membership Level
If you are using account memberships, then the currently logged in user’s membership level will be assigned to the global membership tag.
{% if current_membership %}
{% if current_membership.name == 'VIP' %}
<h1>Welcome back!</h1>
{% endif %}
Back to Documentation