The Anqi CMS provides high flexibility and strong organizational capabilities in content display, which is mainly reflected in its support for template file types and directory structures.Understanding these conventions and mechanisms can help you customize the appearance and layout of your website more efficiently.

The core structure and conventions of template files

Firstly, Anqi CMS stores all template files used for front-end display in the root directory of the site/templateIn the folder. Each independent website theme or template set should have its own folder under this directory, for example, a folder nameddefaultof the template theme, all its files will be placed in/template/default/.

In this theme folder, there is a crucialconfig.jsonFile.This configuration file is like the 'ID card' of the template, defining the template's name, version, author, creation time, and other basic information.template_typeThat is, the adaptation type of the template, which determines how the website responds to visits from different devices:

  • Adaptive template (template_type: 0)This template design can automatically adjust the layout to fit various screen sizes. Whether the user accesses it through a computer, tablet, or smartphone, they will have a good browsing experience.
  • Code adaptation template(template_type: 1)In some cases, you may need to provide completely different code and styles for different devices. Code adaptation mode allows you to create independent template files for mobile content.
  • PC+手机独立站点模式(English)template_type: 2):这是最严格的区分模式,系统会根据访问设备自动跳转到不同的域名(例如English)www.example.comandm.example.com),并加载对应的模板。(English)

No matter which adaptation mode is used, the template file is used uniformly.htmlas a suffix. And the styles (CSS), JavaScript scripts (JS) and images, etc., static resources involved in the template are recommended to be stored separately./public/static/Directory, to achieve front-end and back-end separation, convenient for management and optimization of loading speed.

On template content writing, AnQi CMS adopts the syntax similar to Django template engine. Variables are used with double curly braces{{变量名}}to output, and conditional judgments (such as)if)、loop control (such asfor)et logical operations, use single curly braces and percent signs{% 标签名 %}to define, and must end with the corresponding closing tag (such as{% endif %}/{% endfor %})Close the parenthesis to ensure the integrity of the logical structure. To ensure the correct display of page content, all template files should be uniformly encoded in UTF8.

Flexible and diverse directory organization mode

The secure CMS provides two main directory organization modes to meet the needs of projects of different scales and complexities:

1. 文件夹组织模式(Folder Organization Mode)

This pattern tends to classify template files with similar functions into logically clear subfolders, forming a modular structure. For example:

  • 公共代码片段:Similar to page headers (header) and footers (footer) that repeat on all pages, they are usually placedbash.htmlFile content for other templates to reference. Some reusable UI components such as sidebars, breadcrumbs, etc. may be stored inpartial/the directory.
  • Home page template: The home page of the website is usuallyindex/index.html.
  • Content model related templatesFor different content models such as articles, products, etc., folders named after the model table will be created. For example, if there is an "article" model, you might seearticle/index.html(Article Model Homepage)、article/list.html(Article List Page)、article/detail.html(Article Detail Page)。
  • Template for Specific Content Items:Security CMS allows you to specify independent templates for individual articles, products, or categories. For example, you can create a template for an article with ID 10article/detail-10.html, or create a template for a category with ID 5article/list-5.html.
  • Other Function PageLike single page(page/detail.html), Comment List(comment/list.html), Online Message(guestbook/index.html), Search Results(search/index.html), tag list (tag/list.html)as well as error pageserrors/404.html/errors/500.html)also have their recommended storage paths.
  • Mobile templateIf your website uses code adaptation or PC+mobile independent mode, the mobile template files will be stored uniformly.mobile/In the subdirectory, its internal structure is similar to that of the PC端 template, making it convenient for separate management and maintenance.

The advantages of this model are clear structure and ease of management, especially for large websites or projects with complex content models.

2. Flat File Organization Mode

For websites with relatively simple structures and content types that are not too complex, the flat mode offers a more concise choice. In this mode, most template files are placed directly in the root directory of the template theme, with file names distinguished by prefixes to indicate their functions, such as:

  • Public code and fragments: Still will bebash.htmlandpartial/directory.
  • Home page template: It is directindex.html.
  • Content model related templates: The article model home page may bearticle_index.html, The detail page isarticle_detail.htmlEnglish list page isarticle_list.html.
  • Other Function PageFor example:guestbook.html(Online Message),page.html(Single page detail),search.html(Search page) and others.
  • Mobile template: Similarly,mobile/The catalog will be used to store the flattened template files for the mobile end.

The advantages of this pattern are that file search is more direct, reducing hierarchical nesting, and is suitable for quick development and maintenance.

A meticulous and customized application

The template system of Anqi CMS not only supports these predefined directory structures and filenames, but also gives users great freedom of customization.In addition to the default name templates searched by the system, you can also specify custom template files in the background for individual content items (such as an article, a product), specific categories, or even a single page.

This means that even if all articles are set to defaultarticle/detail.htmlyou can still specify a template for a particular articlearticle/special-detail.htmlor for the single page "About Us"page/about.htmlTemplate. This mechanism allows the content display to fully meet your operational needs, achieving a highly personalized content layout.

In summary, Anqi CMS ensures that you can easily manage the content display of your website with its clear template file type definition, flexible directory organization mode, and powerful backend customization capabilities. Whether you are building a simple corporate website or managing complex multi-site content, you can handle it with ease.


Common Questions (FAQ)

  1. 问:How to specify a custom template for a single article, category, or page in the background?答:You can find options such as "Document Template", "Category Template", or "Single Page Template" in the "Other Parameters" or "Advanced Settings" area when editing articles, products, categories, or single pages. Here you can enter the filename of your custom template (for examplespecial_article.htmlorpage/about.html),System will prioritize loading the specified template when the content item is accessed.

  2. 问:If my website wants to use different templates on both PC and mobile ends but does not want to maintain two independent domains, which type of template adaptation should be chosen?答:In this case, you should choose “Code Adaptation (template_type: 1)” mode. You can create amobile/Subdirectory, and place the corresponding mobile template files in it.The Anqi CMS will automatically identify and load the PC or mobile template based on the access device, without the need for additional configuration of a separate mobile domain.

  3. 问:I want to use a flat file organization pattern, but I don't know how to name the files corresponding to each page?答:In flat mode, the core principle is to reflect the content and function of the page through the filename. For example, the homepage of a website is usuallyindex.html;the homepage of an article model can bearticle_index.html,and the article list page isarticle_list.htmlDetails page forarticle_detail.html; For a single page, it is directly named aspage.htmlorpage-{ID}.html. For function pages such as comment lists, message boards, search results, etc., they are usually named in the form of功能名_list.htmlor功能名.html, such ascomment_list.htmlorguestbook.html. You can refer to the official documentation of Anqi CMS to get the complete list of naming conventions.