In AnQiCMS, the organization and naming conventions of template files play a decisive role in the final presentation of website content.Understanding these conventions can enable us to control the visual and functional presentation of the website more efficiently and flexibly.
The 'home' of the template file:/templateDirectories and.htmlSuffix
When we start working on the template design of AnQiCMS, we first come across the root directory./templateFolder.This is the unified storage place for all website templates.This means that no matter how many sets of themes we create, they will each have their own subdirectories under this directory, maintaining a clear organizational structure.config.jsonFile, used to define the name, version, author, and most importantly, of the topic.Template type (template_type)).This type setting, such as 'auto', '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 standardized with.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 the HTML structure.<div>the tag{{变量}}显示数据,或者使用English{% if 条件 %}and{% for 循环 %}This label is used to control the display and layout 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 uniformly is the key to ensure that the content is displayed normally and to avoid garbled characters.
精准控制内容展示的约定English
AnQiCMS through a set of intelligent naming conventions, allows template files to automatically match and render corresponding content.This greatly simplifies the complexity of backend settings and also provides fine-grained control capabilities.
默认模板文件的自动匹配English是其核心特性之一。例如,系统会默认寻找Englishindex/index.html作为网站首页,English{模型table}/detail.htmlAs a model detail page,{模型table}/list.htmlAs a list page. These conventions allow content to be displayed according to preset styles in the absence of special specifications. Error pages such aserrors/404.htmlanderrors/500.htmlAlso follows similar conventions, ensuring that the website can still prompt users friendly in abnormal situations.
Furthermore, AnQiCMS also supportsCustomize template for specific content ID or category IDEnglish translation: For example, if we want a specific document (such as a document with ID 10) to have a unique detail page layout, AnQiCMS will first look for{模型table}/{文档id}.html[for example]article/10.html)。Similarly, for a list page of a specific category, the system will try to load{模型table}/list-{分类id}.html.This highly customized capability allows us to provide exclusive display effects for important content or special topics without modifying the general template.page/{单页面id}.htmlor more descriptivepage/about.html, and associate it in the background to achieve a highly personalized page layout.
For mobile adaptation, ifconfig.jsonis configured with 'Code Adaptation' or 'PC+Mobile' mode, AnQiCMS will automatically identify the visiting device based on access and try to access from/template/mobileLocate the template file with the same structure and naming as the PC end 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 providesboth "folder organization mode" and "flat file organization mode".The former passes through/partialDirectory stores reusable code snippets (such as sidebars, headers and footers), andincludeLabel reference, enhancing code modularity and reusability.The latter places all template files at the same level, distinguishing different pages through specific naming.These two modes each have their own focus, and can be chosen according to the project scale and team habits, but no matter which one, the core lies in achieving an orderly display of content through conventions.
Summary and outlook
AnQiCMS template.htmlsuffixes/templateThe directory structure, as well as 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 us to customize display styles from global to single-point 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, ensuring that information is presented to the target users in a **status**.
Common Questions (FAQ)
问:How to specify a particular template file for a document or category in the AnQiCMS backend? Answer:When editing documents or category pages, 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 in this input box (for example,
download.html),or a path based on naming conventions (for examplearticle/special-detail.html),and make sure that the file exists in the directory of the template theme you are using. AnQiCMS will prioritize loading the specified template when accessing the content.问:If I design different templates for PC and mobile end, 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, save the mobile template file in the current template theme directory under.mobile/In the subdirectory, and maintain the same naming structure as the PC template files. AnQiCMS will automatically prioritize themobile/Find and load the corresponding template file in the catalog.问:Why does the template file use
.htmlsuffix, but it looks nothing like a regular HTML file? Answer:Although the suffix of the template file is.html,but they are not pure static HTML. AnQiCMS uses a Django-like template engine written in Go language, which means that these.htmlFiles can include special template tags and variables. For example{{变量名}}to display data.{% if 条件 %}for logical judgment,{% for 循环 %}Used for data traversal.At runtime, 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.