Build website templates in AnQiCMS, just like designing a beautiful appearance and practical functional framework for a website.Make sure that the carefully designed content is accurately displayed to visitors, and it is crucial to follow some basic template creation conventions.These conventions can not only help you complete template development efficiently, but also ensure the stable operation of the website and the convenience of future maintenance.

1. The organization and coding standards of template files

Firstly, AnQiCMS has specific requirements for thestorage location and namingof template files. All template files.htmlshould have as their file extension, and should be stored in a unified manner./templateThis root directory. If you need to include static resources such as styles (CSS), scripts (JavaScript), or images in the template, please place them in/public/static/In the directory, so that the system can load it correctly.

A point that is easily overlooked but is extremely important isFile encoding. All template files must be unified using UTF8 encoding.Especially for Windows users, be sure to confirm the encoding format when editing and saving template files, otherwise it may cause garbled characters on the page, affecting the user experience.

AnQiCMS supports a variety ofTemplate TypeTo meet the needs of different website display requirements: including responsive (Responsive), code adaptation (Code Adaptation), and PC + mobile independent site (PC + Mobile Independent Site) mode. If you choose code adaptation or PC + mobile independent mode, then you need to create independent template files for the mobile end, which will be stored in the template directory.mobileIn the subdirectory.

Second, template engine syntax and variable naming rules

The AnQiCMS template system is based on a syntax similar to the Django template engine, making dynamic content display very intuitive.

Output of the variableUsing double curly braces{{变量}}The form, for example, to display the document title, you would use{{archive.Title}}. In variable naming, it is recommended to followcamel case naming conventionThis means capitalizing the first letter of each word, which helps maintain consistent coding style, for examplearchive.Id/archive.Titleetc.

Logical control tagsFor conditional judgments and loops, use single curly braces and percent signs, for example{% if 条件 %}/{% for item in list %}. It should be noted that these logical tags usually need oneend tagto define their scope, for example{% endif %}and{% endfor %}. Properly closing tags is crucial to avoid parsing errors.

Three, Template Directory Structure and Automatic Matching Mechanism

A complete AnQiCMS template, in addition to the core HTML files, also needs oneconfig.jsonConfiguration file, used to describe the basic information of the template, such as the template name(name), version(version), authorauthor), and most importantly,Template Type(template_type), andenable status(status). Among them,statusA field is crucial, as it determines which set of templates is currently being used by the system, and only one template can be used in all templates.statusThe value is 1.

AnQiCMS provides twotemplate file organization mode: Folder organization mode and flat mode. These two modes have their own characteristics, but they both aim to provide a clear structure to manage core pages such as home page, model home page, document detail page, list page, single page, search page, etc.No matter which mode you choose, the system has built-in someDefault Custom Template Name RuleAs long as you create template files according to these rules, the system can automatically recognize and apply them without needing to set them separately in the background.

For example, for the article detail page, the system will try to find{模型table}/{文档id}.htmlsuch a template file; for the list page, it is{模型table}/list-{分类id}.htmlThis flexible naming method also supports the creation of unique templates for specific categories or single-page applications, such as creating for the "About Us" pagepage/about.htmlwhich greatly enhances the customization capabilities of the template.

Four, the correct use of common tags and filters

AnQiCMS has a wealth of built-inTemplate tags and filtersThey are a powerful tool for building dynamic content. For example,{% system %}The label is used to get the website name, LOGO, and other global system settings;{% contact %}Used to display contact information;{% tdk %}