In AnQiCMS, the organization and naming conventions of template files play a decisive role in the final presentation of website content.Understanding these conventions allows us to control the visual and functional presentation of the website more efficiently and flexibly.
The 'home' of the template file:/templateDirectory and.htmlsuffix
When we start designing the AnQiCMS template, we first encounter the files in the root directory./templateFolder. This is the unified storage place for all website templates.This means that regardless of how many sets of themes we create, they will each have their own independent subdirectories within this directory, maintaining a clear organizational structure.Each template theme usually includes aconfig.jsonFile, used to define the name, version, author, and most importantly of the subject.Template type (template_type). This type setting, such as "adaptive", "code adaptation", or "PC+mobile", directly affects how AnQiCMS selects and loads templates based on the user's device, providing a foundation for multi-terminal access.
Although all template files are uniformly.htmlAs a suffix, but this does not mean they are simple static HTML pages.AnQiCMS's template engine uses syntax similar to Django, which allows us to embed dynamic content and complex logic in HTML structures.This means we can<div>the tag{{变量}}to display data, or use{% if 条件 %}and{% for 循环 %}Such labels are used to control the display and formatting of content. This design perfectly combines static structure with dynamic data, greatly enhancing the reusability and flexibility of the template.When writing these dynamic templates, using UTF8 encoding is the key to ensuring that the content is displayed normally and to avoid garbled characters.
Precisely control the display of content agreements
AnQiCMS through a set of intelligent naming conventions, enables template files to automatically match and render corresponding content.This greatly simplifies the complexity of backend settings, and also provides fine-grained control capabilities.
Automatically match the default template fileIt is one of its core features. For example, the system will default to findingindex/index.htmlAs the website homepage,{模型table}/detail.htmlAs the model detail page,{模型table}/list.htmlAs a list page. These conventions allow content to be displayed in a preset style when not specially specified. Error pages likeerrors/404.htmlanderrors/500.htmlAlso follows similar conventions, ensuring that the website can still prompt users in a friendly manner in abnormal situations.
Further more, AnQiCMS also supportsCustomize templates for specific content ID or category ID.For example, if we want a specific document (such as a document with ID 10) to have a unique detail page layout, AnQiCMS will prioritize searching for it.{模型table}/{文档id}.htmlfor examplearticle/10.htmlSimilarly, for a list page of a specific category, the system will try to load{模型table}/list-{分类id}.htmlThis high degree of customization allows us to provide dedicated display effects for important content or special topics without modifying the general template.For a single page (such as "About Us"), we can also createpage/{单页面id}.htmlor more descriptivepage/about.htmland associate it in the background to achieve a highly personalized page layout.
For mobile adaptation, ifconfig.jsonconfigured 'code adaptation' or 'PC+mobile' mode, AnQiCMS will automatically identify the visiting device and try to load from/template/mobileLook for the template file with the same structure and naming as the PC end template in the subdirectory.This allows developers to provide a completely different user experience for mobile users, whether it is layout, interaction, or loading speed, all can be optimized specifically.
On the organization of template files, AnQiCMS provides“folder organization mode”and“flattened file organization mode”two choices. The former passes through/partialThe directory stores reusable code snippets (such as sidebars, headers, and footers), andincludeLabel reference, enhances code modularity and reusability. The latter places all template files at the same level, distinguishing different pages through specific naming.These two modes have their respective focuses, and they can be chosen according to the scale of the project and the habits of the team. However, no matter which one, the core lies in achieving an orderly display of content through conventions.
Summary and prospects
AnQiCMS template's.htmlsuffixes/templateThe directory structure, along with the naming and organizational conventions established around it, together constitute the foundation for displaying website content.It not only provides us with powerful flexibility, allowing customization from global to single-point display styles according to needs, but also simplifies template management through an intelligent matching mechanism.This structure is very beneficial for the long-term maintenance of the website, team collaboration, and future functional expansion.A clear template convention helps us operate more skillfully in content management, whether it is for brand promotion, product display, or content marketing, it can ensure that information is presented to the target users in a **state**.
Frequently Asked Questions (FAQ)
Ask: How to specify a specific template file for a document or category in the AnQiCMS backend? Answer:When editing a document or category page, there is usually an option for a "document template" or "category template". You just need to fill in the name of the template file you created (for example
download.html),or a path based on naming conventions (such asarticle/special-detail.htmlMake sure the file exists in the current template theme directory, and AnQiCMS will load the specified template first when accessing the content.Ask: If I have designed different templates for PC and mobile terminals, how does AnQiCMS judge and load the correct template? Answer:When you design different templates for PC and mobile, you need to be in the current template theme directory under
config.jsonIn the file, willtemplate_typeSet to "Code Adaptation" (1) or "PC+Mobile" (2). Then, place the mobile template file in the current theme directory.mobile/In the subdirectory, and keep the naming structure the same as the PC template file. AnQiCMS will automatically prioritize loading from the relevant directory according to the type of device accessed by the user (determined by User-Agent and other methods).mobile/Search for and load the corresponding template file in the directory.Ask: Why do template files use
.htmlsuffix, but it doesn't look like a normal HTML file? Answer:Although the suffix of template files is.htmlBut they are not pure static HTML. AnQiCMS uses a Django-like template engine in Go language, which means that these.htmlThe file can contain special template tags and variables. For example{{变量名}}Used to display data,{% if 条件 %}Used for logical judgment,{% for 循环 %}Used for data traversal. When the website is running, the AnQiCMS server will first parse these tags, fill in the dynamic data, and finally generate and output pure HTML content that the user's browser can recognize.