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

1. Organization and coding specifications of template files

First, AnQiCMS has clear requirements for thestorage location and namingof template files. All template files.htmlshould be named with/templateThis root directory. If you need to include styles (CSS), scripts (JavaScript), or images, etc. static resources in the template, please place them in/public/static/In the directory, this is the way the system can load correctly.

An easily overlooked but extremely important point isFile encoding.All template files must be uniformly encoded in UTF8.Especially for Windows users, it is necessary to confirm the encoding format when editing and saving template files, otherwise it may cause garbled text on the page, affecting user experience.

AnQiCMS supports a variety oftemplate typeTo meet the different display requirements of various websites: including responsive design (Responsive), code adaptation (Code Adaptation) and PC+Mobile Independent Site mode. If you choose code adaptation or PC+Mobile Independent mode, you will need to create independent template files for mobile devices, which will be stored in the template directory under.mobilesubdirectory.

English template engine syntax and variable naming rules

AnQiCMS's template system is based on syntax similar to Django template engine, which makes dynamic content display very intuitive.

Output of variablesUsing double curly braces{{变量}}The form of, for example, to display the document title, you would use{{archive.Title}}. In variable naming, it is recommended to followcamel case naming conventionsThis is the capitalization of the first letter of each word, which helps maintain consistency in code style, for examplearchive.Id/archive.Titleetc.

Logic control tagsFor conditional judgments and loops, use single curly braces and percent signs, for example{% if 条件 %}/{% for item in list %}English needs to be especially noted, these logical tags usually need oneend tagto define their scope of action, for example{% endif %}and{% endfor %}. Properly closing the tag is the key to avoiding parsing errors.

三、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), author (author) and the most importanttemplate type(template_type) andenable status(status)。其中,statusfield is crucial, it determines which set of templates is currently being used by the system, and only one template can be used in all templatesstatusThe value is 1.

AnQiCMS provides two kinds ofTemplate file organization mode:Folder organization mode and flat mode.These two modes have their own characteristics, but both aim to provide a clear structure to manage core pages such as the homepage, model homepage, document detail page, list page, single page, and search page.Default custom template name ruleAs long as you create template files according to these rules, the system can automatically identify and apply them without any need to set them separately in the background.

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

四、常用标签与过滤器的正确使用

AnQiCMS内置了丰富的模板标签和过滤器,它们是构建动态内容的利器。例如,{% system %}Labels are used to obtain website names, LOGO, and other global system settings;{% contact %}Used to display contact information;{% tdk %}