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

Core conventions of template files

AnQiCMS template files, uniformly adopted.htmlThis convention makes the file type clear at a glance and also helps editors with syntax highlighting and intelligent suggestions. All template files are stored in the root directory of the system under./templateIn the folder, each independent template has its own exclusive subdirectory under this main directory. For example, if you have two templates, one nameddefaultand the other namedcustomThen they will be located separately/template/default/and/template/custom/.

In addition to the template file itself, static resources such as images, CSS styles, JavaScript scripts, and others will also be used in the template. These files are managed centrally in/public/static/The content is placed separately from the template file in the directory, which is conducive to the management of static resources, CDN acceleration, and separation from template logic.

When making templates, using UTF8 encoding uniformly is a basic requirement.If the template file uses a different encoding, it may cause garbled text on the page, affecting user experience.Therefore, whether editing the template through a code editor or other tools, make sure the file is saved in UTF8 format.

AnQiCMS template engine syntax, draws inspiration from the Django template engine, and has similarities with Blade syntax, so developers familiar with these languages will find it very easy to get started. It uses double curly braces{{变量}}Output variables, and logical tags such as condition judgment, loop control, etc. use single curly braces and percent signs{% 标签 %}Define, and these logical tags usually need to appear in pairs, for example{% if 条件 %}...{% endif %}Variable naming conventions should also be paid attention to. The system recommends using camelCase (i.e., each word starts with an uppercase letter, such asarchive.Id/archive.Title), except for some special provisions.

The organization structure and configuration file of the template directory

Each template directory will contain aconfig.jsonFile, it is the 'ID card' of the template, containing basic information and configuration of the template. This file describes the template's name, version, author, description, and other metadata, among which one of the most important fields istemplate_typeIt defines the type of template: 0 for adaptive, 1 for code adaptation, 2 for independent mode on computer and phone. 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 categorizes 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.htmlThe file, for reference by other templates.
    • Code snippets (such as sidebars, breadcrumbs) are stored inpartial/the directory.
    • The home page template is usuallyindex/index.html.
    • The home page, detail page, and list page of the content model for articles, products, and other models are organized according to the model table name, for example,{模型table}/index.html(Model home page),{模型table}/detail.html(Document detail page),{模型table}/list.html(Document list page).
    • Other special pages such as the comment list page (comment/list.html) and online message page (guestbook/index.html) and single page detail page (page/detail.html) and search page (search/index.html) and tag homepage (tag/index.html), as well as the error page (errors/404.html,errors/500.html,errors/close.html) also has its corresponding directory and filename.
  2. Flat file organization mode[en]: Another one is the flattened file organization pattern, 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 the filenames. For example:

    • The conventions for public code and code snippets are the same as the folder pattern (bash.htmlandpartial/).
    • The homepage template isindex.html.
    • Templates related to the content model will be prefixed with the model table name, for example{模型table}_index.html/{模型table}_detail.html/{模型table}_list.html.
    • Other special page template filenames become accordinglycomment_list.html/guestbook.html/page.html/search.html/tag_index.html/errors_404.htmletc.

It is worth noting that regardless of the organization model adopted, if the website needs to support a mobile template, a template root directory will be created under it.mobile/Subdirectories, and repeat the above file organization and naming conventions within them 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 allow the system to automatically identify 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 is)article), you can create aarticle/10.htmlIt is displayed specifically in a file.
  • The document list defaults to a custom templateCan be named{模型table}/list-{分类id}.htmlFor example,article/list-5.htmlIt can be used as the list page template for the category ID 5 in the article model.
  • Single page default custom templateCan 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 capabilities of templates.In addition, AnQiCMS also provides high flexibility, supporting more personalized custom naming.page/about.htmlAnd then, when creating the single-page in the background, set the 'document template' field toabout.htmlThe system will prioritize loading according to the custom template path set in the background.

Why are these conventions important?

Follow these naming and structure conventions, not only to keep your template project neat and organized, but also to have multiple benefits:

  1. Improve development efficiencyStandardization naming reduces guessing, allowing developers to quickly locate and modify files.
  2. Simplifies maintenance and collaborationWhether it is teamwork or post-maintenance, a clear structure and uniform naming can reduce communication costs.
  3. Ensure system compatibility:Especially the default naming conventions, allow AnQiCMS to automatically recognize and correctly load templates, avoiding problems caused by non-standard naming.
  4. Beneficial for version upgradesThe system upgrade can effectively reduce compatibility issues caused by structural changes if the template structure conforms to the agreement.

Understanding and mastering the naming conventions and directory structure of AnQiCMS template files is the foundation for every AnQiCMS user to fully utilize its powerful customization capabilities and build high-quality websites.


Common Questions (FAQ)

Q1: Will AnQiCMS completely fail to recognize if my template file is not named according to these conventions?

A1: Not entirely.For some core pages, such as the homepage, model detail page, and list page, AnQiCMS will first try to find templates 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 usually falls back to using the default built-in logic or reports an error.It is strongly recommended to follow the conventions, which ensures that the template is correctly identified and applied, and improves 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 dynamic matching and reuse of templates.{模型table}The table name of the current content model (for example)article/product), while{分类id}or{文档id}This 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 a particular model, without manually specifying the template path for each article or category in the background; the system can automatically identify.