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

In Shopify, online sellers will use the latest version of Liquid- a flexible and safe language. Therefore, online merchants can have an effective tool to solve a significant number of data. In addition, different types of Liquid codes such as objects, tags, and filters, which allows the Shopify store owners to display the stored data in front store beautifully. That is the reason why Liquid is being used in many applications and websites.

Besides, the Liquid provides a chain of strings so that online sellers enable manipulating their storefront according to their preferences. Because of the flexible Liquid code types, it helps the Shopify shops to be multiple-purposed stores. Besides, thank Liquid, it is possible for online merchants to have professional stores websites and manage their stores in their admin dashboard.

How to Cut Down String to Number of Characters in Shopify

About Truncate {#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 (#guide-to-cut-down-string-to-number-of-characters)

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

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.