Skip to main content

Liquid default: How to Set Default Value in Filter

Last updated: October 07 2024

Written and researched by experts at Avada Learn more about our methodology

Maximizing the satisfaction of your customer’s journey is crucial for any Shopify store owner. One effective way to enhance the shopping experience is by setting a default value in the product filter. This ensures that users see the most relevant options right away, saving time and reducing friction in the browsing process. In this guide, we’ll explain how to set a default value in Shopify filters, helping you streamline your store’s navigation and improve overall customer satisfaction.

Table of content

General information about Liquid

Liquid is one of the open-source template languages in Shopify. Liquid is used as the backbone of Shopify to upload dynamic content on the front page. Liquid has been sold since 2006 and now become a good source for a lot of hosted website application such as Jekyll, salesforce desk, and zendesk.

Liquid codes are divided into objects, tags and filters. Objects tell Liquid where to display content on a page. Objects and variable names are denoted by double curly braces. Filters change the output of a Liquid object. There are five main types of filters, including string, number, boolean, nil, and array. Tags create logic and control flow for a template. Tags begin with two curly braces and percent signs. Tags are classified into control flow, iteration, and variable assignment.

In addition, Liquid in Shopify has other filters to support you to upload dynamic content or set specific forms on your front page.

What is default filter

Default filter sets a default value for any variable with no assigned value. The default filter can be used with strings, arrays, and hashes. The default value is given back if the variable resolves to nil or an empty string. Especially, the default value will not respond to a string consisting of whitespace characters.

How to Set Default Value in Filter

For instance, you want to set default to customer name, then you should follow:

Input


Dear {{ customer.name | default: "customer" }}

Output


<!-- If customer.name is nil -->
Dear customer

<!-- If customer.name is "" -->
Dear customer

<!-- If customer.name is "   " -->
Dear

Conclusion

In conclusion, setting a default value in Shopify filters using Liquid is a simple yet effective way to enhance the customer journey on your store. By ensuring that dynamic content is properly displayed even when certain variables are empty, you can streamline the user experience. Follow the steps in this guide to implement the default filter, and you’ll be one step closer to maximizing customer satisfaction.

linkedin
Sam Nguyen is the CEO and founder of Avada Commerce, an e-commerce solution provider headquartered in Singapore. He is an expert on the Shopify e-commerce platform for online stores and retail point-of-sale systems. Sam loves talking about e-commerce and he aims to help over a million online businesses grow and thrive.