As an experienced AnQiCMS (AnQiCMS) website operator, I know the importance of an efficient and easy-to-use template system for website content management and user experience.AnQi CMS does an excellent job in this aspect, providing a strong and flexible template system that makes content presentation intuitive and highly customizable.Now, let's delve deeper into the syntax, variables, and tag formats supported by the AnQiCMS template.

The core of AnQiCMS template system lies in its support forDjango template engine syntaxand its expression is similar to that of popularBlade syntaxThere are many similarities.This means that whether you are familiar with Django templates in the Python ecosystem or Laravel Blade in the PHP world, you can quickly get started with the template creation of Anqi CMS.This design concept greatly reduces the cost of learning, allowing website operators to invest more energy in high-quality content creation and user experience optimization.

On the file organization level, Anqi CMS has clear conventions for template files. All template files are uniformly named using.htmlas file extensions and stored centrally in/templateUnder the directory.This centralized management method makes the template resources clear at a glance, convenient for search and maintenance./public/static/In the directory, it ensures the separation of static resources from template logic.When editing template files, be sure to pay attention to the unified encoding format of UTF-8 to avoid possible page garbling problems, which is the basis for ensuring correct content display.

In terms of data presentation, the Anqi CMS template usesVariablevery intuitive. They usedouble curly braces{{ 变量名 }}to wrap, for example{{system.SiteName}}and can directly output the website name,{{archive.Title}}The article title will be displayed. This concise syntax makes data binding clear at a glance. It is worth noting that variable naming followscamel case naming conventionThis means that each word's first letter is capitalized, which needs to be followed when referencing built-in or custom data, for examplearchive.Id/archive.Title.

In addition to variables, the Anqi CMS template engine also provides richTagto control the page logic and content structure. These tags are usedsingle curly braces and percent signs{% 标签名 %}to define, and most control flow tags requireto appear in pairsThis means there is a start tag and a corresponding end tag, such as the one used for conditional judgments.{% if 条件 %}{% endif %}and loop iteration.{% for item in 列表 %}{% endfor %}This structured syntax ensures the clarity and integrity of the template logic.

The Anqi CMS is built-in with up to thirty-eight commonly used tags, covering all aspects of website content management. These tags greatly simplify the template development work:

  • System and configuration tagssuch assystemUsed to get the global settings of the website (such as website name, Logo, etc.),contactUsed to get contact information,tdkUsed to manage the page Title, Description, and Keywords.
  • Content management tagssuch asarchiveListUsed to retrieve articles, product lists,archiveDetailUsed to display the details of a single article;categoryListandcategoryDetailUsed to handle category lists and details;pageListandpageDetailIt is specifically used for displaying on a single page.
  • Auxiliary and control flow tagsFor examplenavListUsed to build multi-level navigation menus,breadcrumbCan automatically generate breadcrumb navigation,paginationUsed to handle pagination logic,ifandforTags provide powerful conditional judgment and loop iteration functions.
  • Time processing tagsuch asstampToDateCan convert a 10-digit timestamp to a date-time format supported by Go language (such as{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}), which greatly facilitates the display of time data.

In addition, the Anqi CMS template engine supports powerfulFiltermechanisms. By using a pipe symbol after variables|to connect filter names, variables can be processed more finely, and the format is{{变量 | 过滤器名:参数}}For example,{{ item.Description|truncatechars:100 }}Truncates the article description to one hundred characters,{{ item.Content|safe }}It can prevent variables containing HTML content from being automatically escaped. For content fields enabled with Markdown editors on the backend (such asarchiveDetailandcategoryDetailofContentField), Anqi CMS will automatically convert it to HTML to ensure the correct rendering of content.

In summary, the Anqi CMS template system, with its familiar Django-like syntax, combined with clear variable and tag formats, provides a powerful and flexible content presentation platform for website operators.Mastering the usage of these basic grammatical structures and built-in tags will enable you to efficiently customize the appearance of your website, optimize content display strategies, and thereby better attract and retain your target users.


Frequently Asked Questions (FAQ)

1. Q: Why does the page show garbled text after editing the template?

A: Garbled text in template files is usually due to the file