v10.13.0
Count the number of words in some text. This filter takes an optional argument to control the handling of Chinese-Japanese-Korean (CJK) characters in the input string:
- Passing
'cjk'as the argument will count every CJK character detected as one word irrespective of being separated by whitespace. - Passing
'auto'(auto-detect) works similar to'cjk'but is more performant if the filter is used on a variable string that may or may not contain CJK chars.
Input
1 | {{ "Hello world!" | number_of_words }} |
Output
1 | 2 |
Input
1 | {{ "你好hello世界world" | number_of_words }} |
Output
1 | 1 |
Input
1 | {{ "你好hello世界world" | number_of_words: "cjk" }} |
Output
1 | 6 |
Input
1 | {{ "你好hello世界world" | number_of_words: "auto" }} |
Output
1 | 6 |