How to calculate the number of times a keyword appears in a line of string or array in Anqi CMS template?
count
Filters can calculate the number of times a keyword appears in a line string or array (array/slice).
How to use
count
How to use filters:
{{obj|count:keyword}}
For example, calculation欢迎使用安企CMS(AnQiCMS)
Calculation inCMS
The number of occurrences can be written like this:
{{"Welcome to use AnQiCMS (AnQiCMS)"|count:"CMS"}} # Show results 2
Sample Demo
Get the number of times a keyword appears in a line of text
Direct output result:
{{"Welcome to use AnQiCMS (AnQiCMS)"|count:"CMS"}} # Show results 2
Get the number of times a keyword appears in an array
The keywords in the array need to be equal to the value or index of the array, and they need to be completely equal and cannot be partially matched.
{% set values = "splits the string Anqi CMS"|fields %} {{values|count:"the"}} # Show result 1
{% set values = "splits the string Anqi CMS"|fields %} {{values|count:"Anqi"}} # Show result 0