What are the specific conventions for naming template files and directory structures when creating templates in AnQiCMS?

Calendar 👁️ 65

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.

Related articles

How does the modular design of AnQiCMS support personalized customization and secondary development requirements?

The choice of a content management system (CMS) focuses on flexibility and scalability, which is a core concern for many businesses and individual users.AnQiCMS (AnQiCMS) stands out with its unique modular design, demonstrating significant advantages in supporting personalized customization and secondary development, allowing users to create powerful and distinctive websites according to their own needs. ### The Foundation of Modular Design: The Elasticity of Core Architecture Anqi CMS is developed in Go language, which choice itself brings high performance and high concurrency advantages to the system. It is more important

2025-11-07

How to ensure the stability and smoothness of the AnQiCMS website under high concurrent access volume?

When your AnQiCMS website starts to grow rapidly in traffic, even facing the challenge of high concurrency, how to ensure that it can still run stably and respond smoothly is a concern for every operator.As AnQiCMS was well thought out from the start, combined with its underlying technical advantages and some clever operational strategies, we can build a website as solid as a rock.One of the core strengths of AnQiCMS is that it is developed using the Go language.Go language is renowned for its excellent concurrent processing capabilities

2025-11-07

How does AnQiCMS's scheduled publishing feature help the operations team achieve automated content publishing?

In today's fast-paced digital world, the content marketing campaign never stops.Whether it is a corporate website, a self-media platform, or a multi-site matrix, keeping the content timely updated and continuously published is the key to attracting users and enhancing brand influence.However, manual operations often come with inefficiency, prone to errors, and difficult to catch the pain points of **publishing timing.Against this backdrop, the time-release publishing function of AnQiCMS emerged, bringing new possibilities for automated content publishing to the operation team, greatly enhancing the flexibility and efficiency of content operation.Imagine that you no longer need to stare at the clock

2025-11-07

How to optimize website content and promotion strategies through traffic statistics and crawler monitoring data analysis?

In website operation, continuously optimizing content and promoting strategies is the key to improving website performance and attracting target users.AnQiCMS (AnQiCMS) provides us with strong data support with its built-in traffic statistics and crawler monitoring functions, helping us to deeply understand user behavior and search engine interaction, thereby formulating more accurate optimization plans.Understand traffic statistics, gain insights into user preferences The 'Data Statistics' feature of the Anqi CMS backend presents a comprehensive view of the website visit volume.Through intuitive charts and detailed records

2025-11-07

How to choose and apply the adaptive, code adaptation, PC+mobile terminal template mode supported by AnQiCMS?

How to ensure that the content is presented elegantly and efficiently on various devices when building and operating a website is a challenge that every operator has to face.AnQiCMS as a feature-rich enterprise-level content management system, fully considers this point, and provides three flexible template modes of adaptive, code adaptation, and independent sites for PC and mobile phones, allowing us to make **choices according to actual needs.Next, we will delve into the characteristics, application scenarios, and how to configure and use these three modes in AnQiCMS

2025-11-07

How to dynamically display data using Django-style tags and variables in AnQiCMS templates?

AnQiCMS provides a flexible and powerful template system, which adopts a syntax style similar to the Django template engine, making experienced developers able to get started quickly, and it is also very intuitive, even users who are not familiar with template language can dynamically present website content through simple learning.This system, with its concise labels and variable usage, makes data interaction with the front-end page efficient and easy to manage.To fully utilize the AnQiCMS template for dynamic data display, we need to understand its core syntax structure: variables, tags, and filters

2025-11-07

How to precisely filter and display a document list with specific categories, models, or recommended attributes using the `archiveList` tag?

In AnQi CMS, the `archiveList` tag is the core tool for building dynamic content lists, allowing you to flexibly extract and display the content you want from the website's document library.Whether it is to display the latest articles under a specific category, or popular products under a certain content model, or special document topics with specific recommendation attributes, `archiveList` can help you accurately meet these needs through its rich parameter configuration.### Accurately locate content: Classification, Model and Recommendation Attributes First

2025-11-07

How to retrieve the title, content, image, and custom fields of a specific document using the `archiveDetail` tag?

How to use the `archiveDetail` tag in AnQiCMS to finely control the display of document content?AnQiCMS as an efficient and flexible content management system, one of its core advantages lies in its powerful content display capabilities.For each independent article, product detail, or any other 'document' type of content on the website, we hope to fine-tune their display methods on the front page.This is the place where the `archiveDetail` tag really shines.

2025-11-07