Search code examples
filterdotliquid

c# DotLiquid filter truncatewords not working


Problem

This example doesn't work. It returns all five words.

{%assign value = "word word word word word"%}
{{ value | truncatewords: 1 }}

Solution

  • Solution 1

    Instead use an underscore "truncate_words". This returns just one word.

    {%assign value = "word word word word word"%}
    {{ value | truncate_words: 1 }}
    

    Solution 2

    If the namingconvention is set to C# than you should use camelcasing "TruncateWords". This returns just one word.

    {%assign value = "word word word word word"%}
    {{ value | TruncateWords: 1 }}