In AnQiCMS, whether the content can be presented correctly and elegantly to the user largely depends on the organization and naming conventions of the template files.Understand these basic conventions, which can help you design and manage website interfaces more efficiently, ensuring accurate content presentation.
The cornerstone of the template file:/templateDirectory and.htmlSuffix
AnQiCMS has specific requirements for the placement of template files: all template files must be stored in the root directory of the website./templateIn the folder. This directory is the only entry for AnQiCMS to locate and load templates. At the same time, template files are uniformly used.htmlAs a suffix, this is not only a sign of the system recognizing templates, but also conforms to the general habits of front-end development.
When you create or edit template files, you also need to pay special attention to the file encoding.AnQiCMS requires template files to be encoded in UTF-8.If the page uses other encoding formats, it is likely to display garbled characters, which may affect the user experience.For users accustomed to editing in the Windows environment, it is necessary to select UTF-8 format when saving.
Additionally, the CSS stylesheets, JavaScript scripts, and images, etc., which are required by the template, should not be placed directly in/templateUnder the directory. AnQiCMS provides a dedicated location for these static resources./public/static/The catalog. Separating static resources from template files helps improve the loading efficiency and maintainability of the website.
Flexible organization methods: folder mode and flat mode
AnQiCMS provides two main template organization modes to meet the needs of websites of different scales and complexities:
Folder organization mode:This pattern classifies and stores templates by creating subfolders, making the structure clear and easy to manage large projects. For example, the homepage template may be located
index/index.html, and the article detail page template may be locatedarticle/detail.htmlProduct list page template is located atproduct/list.html.For some common code snippets on web pages, such as the website header (header), footer (footer), or sidebar (sidebar), they are usually stored inpartial/In the catalog, and throughincludeTags are referenced at the required locations to achieve code reuse. This hierarchical structure allows developers to quickly locate and modify templates for specific functions, greatly enhancing maintenance efficiency.Flattened file organization mode:For websites with relatively simple structures and a small number of pages, the flat mode may be more convenient.In this mode, most template files are directly stored in the root directory of the template, distinguished by a naming convention for different types of pages.
index.htmlThe article detail page template is:article_detail.htmlThe product list page template is:product_list.htmlThis pattern reduces the directory hierarchy, making files clear at a glance, suitable for rapid development and lightweight maintenance.
No matter which mode you choose, the key is to maintain consistency and follow the naming conventions of AnQiCMS.Because the system will automatically match content with templates based on these conventions to ensure the correct display of content.
Special considerations for mobile devices:mobile/Directory
With the popularity of mobile internet, responsive design or independent mobile pages are becoming increasingly important.AnQiCMS has taken this into consideration and provides good support for mobile templates.
If your website chooses to use the template type 'Code Adaptation' or 'Independent Site for Computer and Mobile', AnQiCMS will look for a folder namedmobile/The subdirectory. Thismobile/The internal structure and file naming rules of the directory are completely consistent with the main template directory (PC end). This means that if you have aarticle/detail.htmlUsed for PC article details, then the corresponding mobile article detail template should be placedmobile/article/detail.htmlThus, AnQiCMS can automatically load and display the corresponding template based on the type of access device, providing a **browser experience** for users of different devices.
The 'ID card' of the template:config.json
Every AnQiCMS template needs an 'ID card'——which is in the template directory ofconfig.jsonThis file contains basic information about the template, allowing AnQiCMS to recognize and manage this template correctly.
config.jsonIt includes some important fields:
nameThe display name of the template, convenient for you to select and identify the template in the background.packageThe name of the template folder, usually a combination of English letters and numbers, serving as the unique identifier of the template.versionThe version number of the template, for tracking and updating.template_typeThis is a keyword field that defines the type of the template. For example,0Represents an adaptive template (a set of templates that fit all devices),1Represents code adaptation (requires an independent mobile directory),2Represents a separate site for computer and mobile.status: indicates the enabled status of the template,0is disabled,1In use. Only one template can be active in all templatesstatusis1template is enabled
byconfig.jsonAnQiCMS not only understands the basic attributes of the template, but can also switch templates and adapt functions accordingly.
Intelligent Matching: Predefined template names
AnQiCMS's another convenient feature lies in its intelligent recognition of certain pages.If you create template files according to the system's preset naming rules, AnQiCMS can automatically apply these templates even if you do not manually set them in the background.This greatly simplifies the template configuration process.
Some common preset template names include:
- Document details page:
{模型table}/{文档id}.htmlor{模型table}/detail.htmlFor example,article/123.htmlIt will match the article with ID 123,article/detail.htmland it will be the default template for all articles. - Document list page:
{模型table}/list-{分类id}.htmlor{模型table}/list.htmlFor example,product/list-45.htmlWill match the product category list with ID 45, andproduct/list.htmlwhich is the default list template for all product categories. - Single page detail page:
page/{单页面id}.htmlorpage/detail.htmlFor example,page/about-us.htmlCan be used as a dedicated template for the "About Us" page.
This intelligent matching mechanism provides a certain degree of flexibility.You can create customized template files for specific documents, categories, or single pages without changing the templates of other general pages.about.htmlSingle page template, just specify the template of this page in the single page management on the back end.page/about.html, and the system will automatically load it.
In summary, the template file naming and directory structure of AnQiCMS is the core of its content display mechanism. By storing all template files uniformly in/templatethe directory, and using.htmlFilename and UTF-8 encoding can ensure that the system correctly identifies and parses it. At the same time, choose folder organization or flattened organization mode according to the scale of the website,配合mobile/Directory processing for mobile display, as well asconfig.jsonFile management template meta-information, capable of achieving efficient template development and maintenance.While the intelligent recognition function of the preset template names further enhances the convenience and flexibility of content matching with templates.Master these conventions, and your AnQiCMS website will be presented to visitors in the most ideal way.
Common Questions (FAQ)
1. If my template file is not in/templatethe directory, or the file extension is not.html, can AnQiCMS still display the content normally?Cannot. AnQiCMS strictly requires that template files be stored in/templatethe directory and named with.htmlAs a file extension, if not used, the system will not be able to recognize and load these templates, resulting in the content not being displayed normally, and even possible page errors.
2. How does AnQiCMS decide which template should be used for a specific page (such as an article or product detail page)?AnQiCMS will decide according to a set of priority rules.Firstly, it will check if a custom template has been specified for this article, category, or single page.article/detail.htmlorproduct/list-123.html)。Finally, if none of the above rules match, the system will fallback to the default general template.
3. Can I use both folder organization mode and flat file organization mode in a template theme at the same time?Technically, you can mix the two modes under a template theme, because AnQiCMS will search for files according to the agreed path. However, to maintain the consistency and maintainability of the template structure, as well as to avoid potential file naming conflicts or confusion, it is strongly recommended that