How to calculate the frequency of a keyword in a string or array in the 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:关键词}}
For example, calculation欢迎使用安企CMS(AnQiCMS)
Calculation inCMS
The number of occurrences can be written like this:
{{"欢迎使用安企CMS(AnQiCMS)"|count:"CMS"}}
# 显示结果
2
Sample Demo
Get the number of times a keyword appears in a line of text
Direct output result:
{{"欢迎使用安企CMS(AnQiCMS)"|count:"CMS"}}
# 显示结果
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 安企CMS"|fields %}
{{values|count:"the"}}
# 显示结果
1
{% set values = "splits the string 安企CMS"|fields %}
{{values|count:"安企"}}
# 显示结果
0