Home > Shopify Development > Liquid default: How to Set Default Value in Filter

How to Set Default Value in Filter in Shopify

Sam Nguyen
Sam Updated: August 11, 2024

Share:

Drive 20-40% of your revenue with Avada
avada email marketing

Would you like to set automatic messages with a flexible form on your front page? You want to maximize the satisfaction of the customer journey. Liquid has a default filter that can help you to establish the automation for your page. The tutorial guide you to set default value in filter.

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

To sum up, default value assists in establishing default value for any variable with no assigned value. Liquid in Shopify supports default filters to set default formula for your website. We hope that the tutorial is helpful to you and let us know your problems, we will address them.


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.

Stay in the know

Get special offers on the latest news from AVADA.