As an experienced CMS website operation personnel of an enterprise, I know the importance of a high-quality, easy-to-maintain template for the successful operation of the website.The template is the facade of content display, which directly affects user experience and search engine optimization.In AnQiCMS, the creation of templates follows a series of basic conventions and strict file encoding requirements, these standards are designed to ensure the efficient operation of the system and the correct rendering of content.

Basic conventions for AnQiCMS template creation

The core of AnQiCMS template creation lies in its simple and powerful conventions, which cover file structure, syntax, and naming conventions, aiming to enable developers to quickly get started and create stable, flexible website interfaces.

Firstly, all AnQiCMS template files are uniformly used as.htmlthe file suffix. These template files are stored in the root directory of the system./templateIn the folder. To maintain the purity of the template file and for easy management, the style files (CSS), JavaScript scripts (JS), and static resources such as images involved in the template need to be classified separately and stored separately./public/static/Within the catalog. This separation design concept ensures that the logic of content display is not interfered with by static resources, improving loading efficiency and maintenance convenience.

AnQiCMS's template engine syntax is similar to Django's template engine, and it also has a similar effect to Blade syntax, making it very easy for developers with relevant experience to master. Variable calls in template files are made using double curly braces{{变量}}The form, presents the data transmitted from the backend directly on the front end. For conditional judgments (such asif), and loop control (such asfor), logical tags use the combination of single curly braces and percentage signs.{% 标签 %}And these logical tags usually need to appear in pairs, for example{% if archive.Id == 10 %}这是文档ID为10的文档{% endif %}This clear syntax structure helps maintain the readability and logic of the template code.

In variable naming, AnQiCMS follows the camel case naming convention (CamelCase), which means the first letter of each word is capitalized, for examplearchive.Id/archive.TitleOf course, some special provisions or built-in variables may be exceptions, but following this general rule can greatly improve the consistency of the code.

AnQiCMS supports various website modes in templates, including adaptive template types, code adaptation template types, and PC+mobile independent site modes. To better adapt to mobile device access, if code adaptation or PC+mobile mode is selected, the system also provides specificallymobileThe directory is used to store independent mobile template files, and its internal directory structure and file naming conventions are consistent with the PC template.

Moreover, AnQiCMS supports some default custom template names, which means that if the template file is named in a specific format and exists, the system will be able to automatically identify and apply it without any additional configuration in the background. For example, the default custom template for documents can be named{模型table}/{文档id}.htmlThe default template for the document list is{模型table}/list-{分类id}.htmlAnd the default template for a single page ispage/{单页面id}.htmlThis intelligent recognition mechanism greatly simplifies the configuration process of templates, and also allows developers to create dedicated templates for specific pages or categories, such as creating for the "About Us" pagepage/about.htmlTo achieve personalized content display.

Encoding requirements for AnQiCMS template files

For AnQiCMS template files, the encoding requirements are clear and non-negotiable: all template files must be uniformly encoded in UTF-8.

UTF-8 is a highly compatible character encoding that can support almost all character sets in the world, including Chinese, English, and various special symbols.If the template file uses a coding format other than UTF-8, it will inevitably lead to garbled page content when the website runs, resulting in the inability to display normally and severely affecting the user experience.

For Windows operating system users, it is particularly important to pay attention to this point.When editing template files, make sure that your text editor or IDE has selected UTF-8 encoding format when saving the file.Many editors may use GBK or other local encodings by default, and if not manually adjusted, it is likely to cause encoding issues after uploading to the server.Adhere strictly to UTF-8 encoding requirements, which is the basis for ensuring the correct display of AnQiCMS website content and system stability.

In summary, the template making conventions of AnQiCMS aim to provide a clear, efficient, and flexible development environment.Understand and follow these conventions, especially the file naming, syntax rules, and UTF-8 encoding requirements, are the key to creating excellent AnQiCMS templates.


Frequently Asked Questions (FAQ)

1. Why does AnQiCMS template files strictly require the use of UTF-8 encoding? What will happen if I use other encoding?

AnQiCMS strictly requires template files to use UTF-8 encoding to ensure correct display of various characters globally, avoiding garbled text issues caused by incompatible encoding.UTF-8 supports a wide range of character sets and is the standard for modern web development.If the template file uses GBK, GB2312 or other non-UTF-8 encoding, when the system tries to parse these files, it will be unable to correctly identify the characters, resulting in garbled text on the page, making the content unreadable, seriously affecting user experience and website professionalism.

2. In AnQiCMS, each template set needs aconfig.jsonfile? What is its main function?

Yes, in AnQiCMS, each independent template needs to include one in its own template directoryconfig.jsonThe configuration file. The main function of this file is to provide basic metadata for the template, such as the name of the template (name), the corresponding template folder name (package), version numberversion)、a brief description (description), author information(author/homepage), and the creation time (created)et al.,template_typeThe field is used to define the type of template (such as adaptive, code adaptation, PC + mobile), andstatusthe field indicates the enabled status of the template.config.jsonAllow AnQiCMS to recognize and manage the installed templates, which is the key to the normal operation and recognition of the templates by the system.

3. How does the "default custom template name" supported by AnQiCMS templates work? How should I make use of it?

AnQiCMS's "default custom template name" is a convenient feature that allows you to create template files according to specific naming rules, so the system can automatically identify and apply these templates without manually specifying them in the background. For example, you can create a template namedpage/{单页面id}.htmlThe file to be used as a template for a specific single page. To use this feature, simply create the corresponding HTML file in your template directory according to the naming format provided in the document (such as Default Custom Template, Default Custom Template for Document List, Default Custom Template for Single Page).This is very useful for scenarios where you need to customize the display effect for a small amount of specific content without manually associating a template each time, which improves development efficiency and flexibility.