Count the number of words in a string

How to calculate the number of words in a string in Anqi CMS template?

wordcountThe filter can calculate the number of words in a string.wordcountWords are separated by spaces. If there are no spaces, the string is considered as a single word. The result is an integer.

Usage Instructions

wordcountHow to use the filter:

{{ obj|wordcount }}

Here is an example demonstration

{{ ""|wordcount }}
{% filter wordcount %}{% lorem 25 w %}{% endfilter %}

Display results

0
25