How to split a line of text into an array by space in Anqi CMS template?
fields
Filters can split a line of text into arrays in a template by spaces. The array defined is a[]string{}
, you can traverse the output results in the subsequent process.
How to use
fields
Usage of filters:
{% set values โโ= "Text content"|fields %}
{% set values โโ= "splits the string Anqi CMS"|fields %} {{values|stringformat:"%#v"}} # Display result []string{"splits", "the", "string", "Anqi CMS"}
Sample Demo
{% set values โโ= "splits the string ๅ ญ CMS"|fields %} {{values|stringformat:"%#v"}} # Display format []string{"splits", "the", "string", "Anqi CMS"} # Traversal output {% for item in values โโ%} ><span>{{item}}</span>/ {% endfor %} # Display result splits/ the/ string/ Anqi CMS/