How to define an array in the template of Anqi CMS?
list
Filters can define arrays in templates. The array defined is a[]string{}
, you can traverse the output results in the subsequent process.
How to use
list
Usage of filters:
{% set values = '["关键词1","关键词2","关键词3"]'|list %}
The string to be converted is wrapped in single or double quotes, using[
/]
To define the beginning and end of an array, use English between internal keywords,
Separate the keywords, which can be wrapped in quotes or ignored.
{% set values = '["安企CMS","AnQiCMS","内容管理系统","免费建站系统","免费模板",4,5]'|list %}
{% for item in values %}
<span>{{item}}</span>/
{% endfor %}
# 显示结果
安企CMS/ AnQiCMS/ 内容管理系统/ 免费建站系统/ 免费模板/ 4/ 5/
Sample Demo
{% set values = '["安企CMS","AnQiCMS","内容管理系统","免费建站系统","免费模板"]'|list %}
# 显示格式:
{{values|stringformat:"%#v"}}
# 遍历输出
{% for item in values %}
<span>{{item}}</span>/
{% endfor %}
# 显示结果
安企CMS/ AnQiCMS/ 内容管理系统/ 免费建站系统/ 免费模板/