How to get the location where a keyword appears in a line of strings or arrays in Anqi CMS template?
index
Filters can calculate where a keyword appears in a line string or array (array/slice). If the string contains multiple keywords to be found, the index returns the first occurrence position. If not found, return -1. Note: If there is Chinese in the string, when calculating the position, one Chinese counts 3 positions.
How to use
index
How to use filters:
{{obj|index:keyword}}
For example, judgment欢迎使用安企CMS(AnQiCMS)
Calculation inCMS
The location where it appears can be written like this:
{{"Welcome to use AnQiCMS (AnQiCMS)"|index:"CMS"}} # Display results 18
Sample Demo
Calculate where a keyword appears in a line of text
Direct output result:
{{"Welcome to use AnQiCMS (AnQiCMS)"|index:"CMS"}} # Display results 18
Calculate where 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|index:"the"}} # Show result 1
{% set values = "splits the string Anqi CMS"|fields %} {{values|index:"Anqi"}} # Show result -1