Home > Shopify Development > Liquid truncate: How to Cut Down String to Number of Characters

Liquid truncate: How to Cut Down String to Number of Characters in Shopify

Sam Nguyen
Sam Updated: May 23, 2024

Share:

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

If you’re working with Shopify’s Liquid and need to limit the length of text, the truncate filter is the perfect tool. In this guide, we’ll show you how to use Liquid truncate to cut down a string to a specific number of characters. This is essential for keeping your store’s content clean and easy to read, especially in product descriptions and other areas with limited space. Learn how to apply it effectively and optimize your Shopify store’s presentation.

How to Cut Down String to Number of Characters in Shopify

About Truncate

The Truncation is referred to as cutting or removing tool in IT field. In fact, the users can use the Truncate to make a string shorter. To make strings fewer resources to store, truncation takes a certain object such as a number or text. By cutting off, it allows the Shopify store owners to type with the maximum number of characters. However, if the program which truncates the first 255 characters data with the submitted or saved information, the additional characters are disregarded. In addition, in case that there is less number of strings than the length of the string, there is an ellipsis (…) will be appended. Because online sellers can shorten their string into their expected characters by truncation, they can take an optional second parameter by themselves. To cut down the string to the number of characters, Shopify store owners can refer through this article How to Cut Down String to Number of Characters.

The way to cut down string to number of charaters

Step 1: Input

Input

{{ "Ground control to Major Tom." | truncate: 20 }}

Step 2: Output

The output will be as below example:

Output

Ground control to...

Custom ellipsis (Click here)

There is an ellipsis (…) by default but the Shopify store owners can modify it with different sequences. The second parameter will take optionally by truncate. In addition, the length of this second parameter takes which is an optional count against the number of characters specified by the first parameter. For instance, the Shopify store owners want to truncate a string to exactly 10 characters, they could use a 3-character ellipsis and then the first parameter of truncate will be used in 3 characters.

The input of this case is:

Input

{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}

Output

Ground control to--

No ellipsis (Click here)

Try to avoid showing trailing characters, the second parameter can pass a blank string.

Input

{{ "Ground control to Major Tom." | truncatewords: 3, "" }}

And then entering the input, the output will be like this:
Output

Ground control to

Conclusion

In conclusion, the Liquid truncate filter is a valuable tool for Shopify store owners to manage text efficiently by limiting the number of characters displayed. By applying it, you can keep your content concise and professional, ensuring that your storefront remains clean and user-friendly. Whether you need custom ellipses or no ellipses at all, truncate provides the flexibility to tailor your text presentation to suit your store’s needs.

Last but not least, we hope that online sellers can have more understanding of Shopify as well as Liquid through other articles like the following list:


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.