How to remove HTML tags from the Anqi CMS template?
striptagsThe filter can remove all HTML tags from the HTML code.
removetagsThe filter can remove specified tags from the HTML code.
Usage method
striptagsHow to use the filter:
{{ obj|striptags }}
removetagsHow to use the filter:
{{ obj|removetags:"标签" }}
You can remove multiple tags, separated by a comma,separated.
For example, to remove<strong><i>Hello!</i></strong>the i tag, it can be written like this:
{{ "<strong><i>Hello!</i></strong>"|removetags:"i"|safe }}
# 显示结果
<strong>Hello!</strong>
Example Demonstration
{{ "<strong><i>Hello!</i></strong>"|striptags|safe }}
{{ "<strong><i>Hello!</i></strong>"|removetags:"i"|safe }}
{{ "<strong><i>Hello!</i><span>AnQiCMS</span></strong>"|removetags:"i,span"|safe }}
# 显示结果
Hello!
<strong>Hello!</strong>
<strong>Hello!</strong>