Liquid truncatewords: How to Cut Down String to Number of Words in Shopify

As an effective marketplace, Shopify is used popularly by million of Shopify stores in whole around the world. In addition, with the lastest of the Liquid, online sellers can easily make up a store with professionalism and beauty. Moreover, the Liquid is open source that allows the Shopify store owners to contribute their homepage without paying any cost. As a flexible and safe language, Liquid is usually used in multiple websites and applications.

In Shopify, online merchants also can manage the multiple-purpose shops in their admin dashboard. Besides, with the combination of Liquid codes types such as objects, tags, and filters, they can solve all dynamic data in their stores. To display the store data beautifully in the front store, it is necessary for the online merchants to customize their Liquid objects or their Liquid filters to change the outputs of objects string. Therefore, it is possible for online sellers to customize their stores in Shopify.

How to Cut Down String to Number of Words in Shopify

About truncatewords

As the definition of the Truncation in the last article Liquid truncate: How to Cut Down String to Number of Characters, we mentioned that Truncation is considered as a cutting or removing tool. Through that tutorial, online sellers totally enable cutting down their strings into the number of words they want by truncation. In addition, the users can use the Truncate to make a string shorter. For this article How to Cut Down String to Number of Words in Shopify will bring the users simple steps to cut their strings with the expected number of words.

The way to cut down string to number of words

Step 1: Input

Input

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

Step 2: Output

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, "" }}

Output

Ground control to

Conclusion

In this article How to Cut Down String to Number of Words in Shopify, we hope that the Shopify store owners enable helping to cut down the string which has the number of words in Shopify. Including the simple steps, online sellers can do it by themselves. Moreover, in this article, the Shopify sellers also have more knowledge about Liquidity in the Shopify. In addition, we hope that online merchants to have more understanding of Shopify as well as Liquid through our chain of articles like the following list: