How to calculate the number of times a keyword appears in a string or array in the Anqi CMS template?
count
The filter can calculate the number of times a keyword appears in a line of string or array (array/slice).
Usage Instructions
count
How to use the filter:
{{obj|count:关键词}}
For example, calculate欢迎使用安企CMS(AnQiCMS)
in the calculationCMS
the number of occurrences, you can write it like this:
{{"欢迎使用安企CMS(AnQiCMS)"|count:"CMS"}}
# 显示结果
2
Here is an example demonstration
Get the number of occurrences of a keyword in a line of text
Directly output the result:
{{"欢迎使用安企CMS(AnQiCMS)"|count:"CMS"}}
# 显示结果
2
Get the number of occurrences of a keyword in an array
The value in the array needs to be equal to the key or index of the array, they must match exactly, not partially.
{% set values = "splits the string 安企CMS"|fields %}
{{values|count:"the"}}
# 显示结果
1
{% set values = "splits the string 安企CMS"|fields %}
{{values|count:"安企"}}
# 显示结果
0