In AnQi CMS, template files are the basis for displaying website content.It is not just a simple HTML file, but a set of blueprints that follow specific conventions and rules. Only by accurately adhering to these conventions can the system correctly parse, render, and display the structure of your website content.Understanding these basic conventions can help you customize and manage your website more efficiently, ensuring that content is presented to visitors in the way you expect.

The storage location and basic format of template files

Firstly, AnQi CMS has specific requirements for the storage location of template files. All template files should be placed uniformly under the root directory of the website./templateIn the folder. Each independent template needs to be in this/templatedirectory to create a dedicated folder, and include a single oneconfig.jsonConfiguration file, this file is like the 'ID card' of the template, informing the system of the template's name, version, author, and most importantly—the template type and enabled status.

And the naming of the template files is very intuitive, they use uniformly.htmlAs a file extension. As for the CSS styles, JavaScript scripts, and static resources such as images used in the template, they need to be stored separately./public/static/In the directory, this can keep the template directory tidy and is also beneficial for website performance optimization.

In addition, a seemingly minor but crucial detail is the file encoding. All template files must be unified in their adoption.UTF-8 EncodingIf other encoding formats are used, the page content may appear garbled and cannot be displayed normally.For users who edit templates on the Windows system, be sure to save the file in UTF-8 format when saving.

AnQi CMS template engine and syntax

The template core of AnQi CMS adopts a syntax similar to the Django template engine, which allows developers familiar with Blade templates or similar syntaxes to get started quickly.

The reference to data variables is very direct, you just need to enclose the variable name in double curly braces, for example{{变量名}}. The system will automatically fill in the corresponding data into these positions according to the context of the current page.

For more complex logic control, such as conditional judgment,if)、looping over(forBrackets such as need to be defined using single curly braces and the percentage sign, for example{% if 条件 %}It is noteworthy that these logical tags usually need a corresponding end tag, such as{% endif %}or{% endfor %}Pairwise structures are formed to ensure the integrity of logical blocks.On variable naming, Anqi CMS recommends using CamelCase naming conventions, where the first letter of each word is capitalized, which helps improve the readability and consistency of the code.

The type and refinement of the template

AnQi CMS provides various template types to meet different website construction needs, including adaptive templates, code adaptation templates, and PC + mobile independent site mode. This isconfig.jsonin the filetemplate_typeSet the field. If you choose code adaptation or PC+mobile independent mode and want to provide an independent template for mobile devices, then you need to create a folder namedmobileThe subdirectory, and in it, store the mobile template files in a structure similar to the PC template.

On file organization, AnQi CMS provides two main modes: folder organization mode and flat file organization mode.No matter which mode, the system has preset some default template file names. As long as these files exist in your template directory, the system can automatically apply them without any separate settings in the background.

For example:

  • Home pageIt is usuallyindex/index.htmlorindex.html.
  • Content model home page(such as the article list page or product list page) can be{模型table}/index.htmlor{模型table}_index.html.
  • Document detail page(such as a single article or product detail) can be{模型table}/detail.htmlor{模型table}_detail.html.
  • Category list pageis{模型table}/list.htmlor{模型table}_list.html.
  • a single page detail pagelike the 'About Us' page, can bepage/detail.htmlorpage.html.

It is more powerful that, Anqi CMS supports the use of custom templates for specific content items.This means you can specify a completely independent template file for a specific document ID, category ID, or single page ID.For example, if you have an article with ID 10 that needs special display, you can create aarticle/10.htmltemplate; or create a single 'About Us' pagepage/about.htmlThe template, and configure the page to call this custom template in the background. This flexibility allows the presentation of website content to be highly personalized.

Intelligent mapping of content and template

After understanding these conventions, you will find that Anqi CMS does a very intelligent job in combining backend data with frontend templates.When a visitor requests a page, AnQi CMS will automatically search and render the most suitable template file based on the URL, backend configuration, and current template directory structure, and pass related data (such as article titles, content, category information, etc.) to the template through predefined tags and variables.

For example, on the document detail page, you can use{{archive.Title}}to get the article title, use{% archiveDetail with name="Content" %}to display the article content; on the category list page, you can use{% categoryList categories with moduleId="1" %}to iterate through the article categories, and use{% for item in categories %}Output the name and link of each category. These built-in tags and variables greatly simplify the interaction process between content and templates, allowing you to focus on content creation and page design.

Summary

The AnQiCMS template file conventions aim to provide a standardized and flexible framework.By placing files in the correct location, using unified encoding, adhering to similar Django template syntax, and making good use of its various template types and custom naming mechanisms, you will be able to fully utilize the powerful functions of the AnQi CMS to build a website with clear structure, rich content, and strong visual appeal.Familiarize yourself with and apply these basic conventions, which are a key step in your efficient operation of the Anqi CMS website.


Frequently Asked Questions (FAQ)

1. Why does the content displayed by my website template show garbled characters?If your website template displays garbled text, the most common reason is that the encoding format of the template file is incorrect.The AnQi CMS requires all template files to be encoded in UTF-8.Please check your.htmlFiles, make sure they are saved in UTF-8 format. If you are using a Windows system, pay special attention to selecting the UTF-8 encoding option when saving files.

2. Why is the custom template I set for a category or document not working on the frontend?There may be several reasons for this situation:

  • Template file does not exist or the path is incorrect: Make sure you have created the corresponding custom template file in the template directory, and the file name and path must match the settings in the background. For example, if the background is set todownload.htmlThen the file should be in the root directory of the current template, not in a subfolder, or if set toarticle/download.htmlthen the file should betemplate/您的模板名称/article/download.html.
  • Template type does not match:Checkconfig.jsonoftemplate_typeDoes it match your actual website requirements (such as PC + mobile independent mode)? If it is a mobile template, is the file placed inmobiledirectory.
  • Cache problem:Try to clear the system cache of Anqi CMS, sometimes the cache can cause the new template to not take effect immediately.

3. How does AnqiCMS identify which template file should be used for the homepage, article detail page, or category list page of my website?SafeCMS identifies through a set of intelligent matching rules.Firstly, it will judge the current page is the homepage, article detail, category list, or other types based on your website URL structure.Then, it will look for the corresponding template file in the currently enabled template directory, following the predefined default naming convention, for exampleindex.htmlrepresents the home page,{模型table}/detail.htmlRepresents document details,{模型table}/list.htmlRepresent a category list. If you set specific content items in the background (such as a category or document ID