AnQiCMS as a content management system known for its efficiency and flexibility, also has a clear set of conventions in template creation, aimed at helping developers and operators build structured and easy-to-maintain websites.Understanding these conventions is a key step in efficiently using AnQiCMS for website customization and content display.

The core conventions of template files

AnQiCMS's template files are unified using.htmlAs a file extension. This convention makes the file type clear at a glance and also helps editors with syntax highlighting and intelligent hints. All template files are stored in the root directory of the system./templateIn the folder, each independent template has its own exclusive subdirectory under the main directory. For example, if you have two templates, one nameddefault, and another namedcustomThey will be located separately/template/default/and/template/custom/.

In addition to the template file itself, the template will also use images, CSS styles, JavaScript scripts, and other static resources. These files are centrally managed in/public/static/Place the directory separately from the template file, which is beneficial for managing static resources, CDN acceleration, and separating from template logic.

When creating templates, it is a basic requirement to use UTF8 encoding uniformly.If the template file uses other encoding, it may cause the page to display garbled characters, affecting user experience.Therefore, whether editing a template through a code editor or other tools, make sure the file is saved in UTF8 format.

The syntax style of AnQiCMS template engine, which draws inspiration from the Django template engine, has similarities with Blade syntax, making it very easy for developers familiar with these languages to get started. It uses double curly braces{{变量}}output a variable, while conditional judgments, loop controls, and other logical tags are represented by single curly braces and percent signs{% 标签 %}defined, and these logical tags usually need to appear in pairs, such as{% if 条件 %}...{% endif %}. Variable naming conventions should also be paid attention to, the system recommends using camel case (i.e., each word has its first letter capitalized, such asarchive.Id/archive.Title), except for some special provisions.

The organization structure and configuration file of the template directory

Each template directory will have oneconfig.jsonFile, it is the 'identity card' of the template, containing basic information and configuration. This file describes the name, version, author, description, and other metadata of the template, one of the most important fields beingtemplate_typeIt defines the template type: 0 for adaptive, 1 for code adaptation, 2 for independent computer + mobile mode. Another key field isstatusIt indicates whether the template is being used, only one template can be used at a time.statusThe value is 1.

To adapt to different development habits and project scales, AnQiCMS provides two main template file organization modes:

  1. Folder organization modeThis pattern classifies different types of page templates into their respective folders, making the structure clear and easy to search and manage. For example:

    • Common code (such as headers and footers) is usually placed inbash.htmlIn the file, for reference by other templates.
    • Code snippets (such as sidebars, breadcrumbs) are stored in.partial/directory.
    • The homepage template is usually.index/index.html.
    • The home, detail and list pages of articles, products and other content models are organized according to the model table name, for example{模型table}/index.html(Model Home),{模型table}/detail.html(Document detail page),{模型table}/list.html(Document list page).
    • Other special pages such as comment list pages (comment/list.html), Online留言页 (guestbook/index.html) of single page detail pagepage/detail.html) of search pagesearch/index.html) of tag homepagetag/index.html), as well as the error page (errors/404.html,errors/500.html,errors/close.html) also has its corresponding directory and filenames.
  2. Flat file organization mode: Another one is the flattened file organization mode, as the name implies, in this mode, most template files are directly placed in the template root directory, and types are distinguished by the prefix of filenames. For example:

    • The convention for public code and code snippets is the same as the folder pattern (bash.htmlandpartial/)
    • The home page template isindex.html.
    • Templates related to content models will be prefixed with the model table name, for example{模型table}_index.html/{模型table}_detail.html/{模型table}_list.html.
    • The template file name for other special pages will accordingly changecomment_list.html/guestbook.html/page.html/search.html/tag_index.html/errors_404.htmletc.

It is noteworthy that regardless of the organization mode, if the website needs to support mobile template, a directory will be created under the template root.mobile/Subdirectory, and repeat the above file organization structure and naming conventions to provide page layouts dedicated to mobile devices.

Specific template naming conventions and customization flexibility.

AnQiCMS has set more specific default naming conventions for some core page types, which can make the system automatically recognize and apply templates, greatly simplifying backend configuration.

  • Document default custom templateCan be named{模型table}/{文档id}.htmlThis means that if you have an article model (assuming the table name isarticle) with an article ID of 10, you can create aarticle/10.htmlFiles to display it specifically.
  • Default custom template for document listCan be named{模型table}/list-{分类id}.htmlFor example,article/list-5.htmlCan be used as a list page template for the article model with category ID 5.
  • Default custom template for single pageCan be namedpage/{单页面id}.htmlFor example, for a single page with ID 1, the system will try to findpage/1.html.

These default conventions greatly enhance the automation application capabilities of the template.In addition, AnQiCMS also provides high flexibility, supporting more personalized custom naming.For example, if you want to design a unique template for the 'About Us' single page, you can name the template file aspage/about.htmlThen, when creating a single-page application in the background, set the "document template" field toabout.htmlThe system will load the custom template path set in the background first.

Why are these conventions important?

Adhering to these naming and structural conventions not only keeps your template project neat and orderly, but also has many benefits:

  1. improve development efficiency: Standardized naming reduces guessing, allowing developers to quickly locate and modify files.
  2. Simplify maintenance and collaboration: Whether it is team collaboration or post-maintenance, a clear structure and unified naming can reduce communication costs.
  3. Ensure system compatibilityEspecially the default naming convention allows AnQiCMS to automatically recognize and correctly load templates, avoiding problems caused by non-standard naming.
  4. Beneficial for version upgrades: When the system is upgraded, if the template structure conforms to the agreement, it can effectively reduce compatibility issues caused by structural changes.

Understand and master the AnQiCMS template file naming and directory structure conventions, which is the foundation for every AnQiCMS user to exert their powerful customization capabilities and build high-quality websites.


Frequently Asked Questions (FAQ)

Q1: If my template file is not named according to these conventions, will AnQiCMS completely fail to recognize it?

A1: It is not entirely. For some core pages such as the homepage, model detail page, and list page, AnQiCMS will first try to find the template with the default naming pattern.If not found, it will continue to search for the specified custom template file in the background settings.If both are not found, the system will usually revert to using the default built-in logic or error reporting.But it is strongly recommended to follow the conventions, which can ensure that the template is correctly identified and applied, and improve the development and maintenance efficiency.

Q2: Why do some default template names contain{模型table}or{分类id}Such placeholders? How will they be replaced?

A2: These placeholders are designed to achieve the dynamic matching and reuse of templates.{模型table}The database table name of the current content model (for examplearticle/product),while{分类id}or{文档id}It will be replaced with the corresponding category ID or document ID. The benefit of this is that you can create independent templates for specific categories or specific documents under specific models, without having to manually specify the template path for each article or category in the background, the system can automatically identify.