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 content layout of the website more efficiently.

Core structure and conventions of template files

First, 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 in this directory, such as a folder nameddefaultfor the template theme, all its files will be placed in/template/default/.

Inside this theme folder, there is a crucialconfig.jsonFile. This configuration file is like the 'ID card' of the template, defining its name, version, author, creation time, and other basic information.What is more, it also indicates the template'stemplate_typewhich is the type of template adaptation, determining how the website responds to access from different devices:

  • Adaptive template(template_type: 0)This template design can automatically adjust the layout to fit various screen sizes, whether users access it through computers, tablets, or mobile phones, they can enjoy 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. The code adaptation mode allows you to create independent template files for mobile content.
  • PC+Mobile independent site mode(template_type: 2): This is the strictest distinction mode, the system will automatically jump to different domain names (such aswww.example.comandm.example.com) and load the corresponding template.

Regardless of which adaptation mode is used, the template file is used uniformly.htmlAs a suffix. And the static resources such as styles (CSS), JavaScript scripts (JS), and images involved in the template are recommended to be stored separately./public/static/The catalog, to achieve front-end and back-end separation, facilitating management and optimizing loading speed.

On template content writing, AnQi CMS adopts syntax similar to Django template engine. Variables are enclosed in double braces{{变量名}}to output, and conditional judgments (such asif), loop control (such asforUse single curly braces and percent signs for logical operations{% 标签名 %}And define them with corresponding end tags such as{% endif %}/{% endfor %}) Close 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

AnQi 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:

  • Public code snippets: Parts such as headers and footers that appear repeatedly on all pages are usually placedbash.htmlFiles for reference by other templates. Some reusable UI components such as sidebars, breadcrumbs, and others may be stored inpartial/directory.
  • Home page template: The home page of the website is usuallyindex/index.html.
  • Templates related to content modelFor 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 Home Page),article/list.html(Article List Page),article/detail.html(Article Detail Page).
  • Specific Content Item Template: AnQi 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 10.article/detail-10.htmlOr create a template for a category with ID 5.article/list-5.html.
  • Other feature pages: Like a 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) and error page (errors/404.html/errors/500.html)et al, also have their respective recommended storage paths.
  • Mobile end template:If your website uses code adaptation or PC+mobile independent mode, the mobile template files will be stored uniformly inmobile/In the subdirectory, its internal structure is similar to that of the PC template, making it convenient for independent management and maintenance.

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

2. Flat File Organization Mode

For websites with relatively simple structures and less complex content types, a flat mode offers a simpler choice. In this mode, most template files are placed directly in the root directory of the theme, with file names distinguished by prefixes, for example:

  • Public code and fragments: Will still havebash.htmlandpartial/Directory.
  • Home page template: Directly isindex.html.
  • Templates related to content model: The article model home page might bearticle_index.html, The detail page isarticle_detail.html, List page isarticle_list.html.
  • Other feature pages: such asguestbook.html(Online留言),page.html(Single page detail),search.html(Search page) and others."),
  • Mobile end template: Similarly,mobile/The catalog will be used to store the flat template files corresponding to the mobile end.

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

Customized application with meticulous attention to detail.

The Anqi CMS template system not only supports these agreed-upon directory structures and filenames, but also gives users great freedom to customize.In addition to the default name template search performed by the system, you can also specify a custom template file in the background for a single content item (such as an article or a product), a specific category, or even a single page.

This means that even if all articles are using the defaultarticle/detail.htmlyou can still specify a template for a particular articlearticle/special-detail.htmlor for the 'About Us' single pagepage/about.htmlTemplate. This mechanism allows the content display to fully meet your operational needs and achieve 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 site or managing complex multi-site content, you can do so with ease.


Frequently Asked Questions (FAQ)

  1. How to specify a custom template for a single article, category, or page in the backend?Answer: You can find options such as 'Document Template', 'Category Template', or 'Single Page Template' and others 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 example,special_article.htmlorpage/about.html), the system will load the template you specified when the content item is accessed.

  2. Ask: 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 I choose?Answer: In this case, you should select the "code adaptation (template_type: 1)" mode. You can create a template in the theme folder.mobile/Subdirectory, and place the corresponding mobile template files in it.The Anqi CMS automatically identifies the visiting device and loads the PC or mobile template without the need for additional configuration of a separate mobile domain.

  3. Ask: I want to use a flattened file organization pattern, but I don't know how to name the files corresponding to each page?Answer: In flat mode, the core principle is to reflect the content and function of the page through the filename. For example, the home page of a website is usuallyindex.html; the home page of the article model can bearticle_index.html; the article list page isarticle_list.htmlDetail page isarticle_detail.htmlIf it's a single page, name it directlypage.htmlorpage-{ID}.htmlFor function pages such as comment lists, message boards, and search results, it is also usually named in the form of功能名_list.htmlor功能名.htmlsuch ascomment_list.htmlorguestbook.html. You can refer to the official document of Anqi CMS for the complete naming convention list.