As a senior security CMS website operation person, I know that a high-efficiency and standardized template system is crucial for the long-term development of the website and the efficiency of content management.AnQi CMS with its concise and efficient architecture and Django-style template engine, provides great convenience for content creators and operators.During the template creation process, adhering to certain basic conventions and recommended directory structures can effectively improve development efficiency, reduce maintenance costs, and ensure the flexible display of website content.
Basic conventions for Anqi CMS template creation
The template creation of Anqi CMS follows a series of basic conventions to ensure the consistency, maintainability, and system compatibility of template files.
Firstly, all template files are uniformly used..htmlAs a file suffix, and placed in the root directory of the website/templateIn the template folder. This makes it easier for the system to recognize and load, and also makes the management of template files more systematic.Static resources such as CSS stylesheets, JavaScript scripts, and images related to the template should be stored separately./public/static/The catalog, to achieve separation of static and dynamic, optimize loading performance.
On the template syntax level, Anqi CMS adopts a label marking method similar to the Django template engine. Variable output uses double curly braces.{{变量}}To define, for example.{{archive.Title}}Used to output the document title. Logical tags such as condition judgment and loop control are represented by single curly braces and percentage signs{% 标签 %}Define. It should be noted that all logical tags must appear in pairs and be terminated using the corresponding end tags, for example{% if archive.Id == 10 %}这是文档ID为10的文档{% endif %}Ensure the integrity of the logical block.
The naming conventions of variables are also very important. Anqi CMS recommends using camel case naming conventions, where the first letter of each word is capitalized, for examplearchive.Idandarchive.TitleHowever, some variables specified by the system are exceptions. Adhering to this naming convention helps improve code readability and reduce potential errors.
To avoid page garbling issues, all template files must be uniformly encoded in UTF-8 format.For users editing templates in the Windows environment, it is necessary to select UTF-8 encoding when saving.
The Anqi CMS template system supports various website modes, including adaptive template types, code adaptation template types, and PC + mobile end independent site modes. Among them, if you choose code adaptation or PC + mobile end mode, you need to create a separate template for mobile devices, and these mobile templates should be stored in the main template directory.mobileThe internal structure is consistent with the PC template in the subdirectory.
The system also supports some default custom template names. As long as these template files are created in a specific format, even if they are not set separately in the background, the system can automatically apply them.For example, the default custom template name format for the document can be{模型table}/{文档id}.htmlThe default format for document lists can be{模型table}/list-{分类id}.htmlAnd the default format for a single page can bepage/{单页面id}.htmlThis mechanism provides more detailed template control for specific content.
Recommended directory structure for AnQi CMS template creation
Standard directory structure is the foundation for template development and maintenance. The root directory of AnQi CMS template is/templateEach template set needs to create its own independent directory in this folder.
Each template directory must contain oneconfig.jsonConfiguration file, used to describe the basic information of the template. This file plays the role of the template's 'ID card', and the system identifies and manages the template through it.config.jsonThe content of the file usually includes the following fields:name(Template name),package(Folder name of the template, only supports letters and numbers),version(Template version),description(Template introduction),author(Template Author),homepage(Author's Website),created(creation time),template_type(Template Type, 0 for responsive, 1 for code adaptation, 2 for computer + mobile) andstatusThe template usage status, 0 means not enabled, 1 means in use). It is worth noting that only one set of templates can be used in all templates.statusThe value is 1.
The template directory and file organization methods of AnQi CMS mainly have two types: folder organization mode and flattened file organization mode.
InFolder organization modeBelow, template files are grouped into different subdirectories according to function or page type, forming a hierarchical structure. For example:
- Public code file:
bash.htmlThis section is used to store page headers, footers, and other parts that may be inherited by each page. - Code snippet catalog:
partial/This section is used to store reusable code snippets such as sidebars and breadcrumbs. - Home:
index/index.html. - Model homepage:
{模型table}/index.htmlsuch asarticle/index.html. - Document detail page:
{模型table}/detail.htmlCan also be customized for a specific document{模型table}/detail-{文档ID}.html. - Document list page:
{模型table}/list.htmlOr for a specific category{模型table}/list-{文档分类ID}.html. - Comment list page:
comment/list.html. - Online留言页:
guestbook/index.html. - a single page detail page:
page/detail.htmlOr for a specific single pagepage/detail-{单页ID}.html. - Search Page:
search/index.html. - Tag homepage:
tag/index.html. - Tag document list page:
tag/list.html. - error page:
errors/404.html/errors/500.html/errors/close.html. - Mobile template directory:
mobile/The internal structure is consistent with the PC template.
AndFlat file organization modeMost of the template files are placed directly in the template root directory, distinguished by file naming to differentiate between different page types. For example:
- Public code fileandCode snippet catalogThe same as folder mode.
- Home:
index.html. - Model homepage:
{模型table}_index.html. - Document detail page:
{模型table}_detail.html. - Document list page:
{模型table}_list.html. - Comment list page:
comment_list.html. - Online留言页:
guestbook.html. - a single page detail page:
page.htmlOr for a specific single pagepage-{单页ID}.html. - Search Page:
search.html. - Tag homepage:
tag_index.html. - Tag document list page:
tag_list.html. - error page:
errors_404.html/errors_500.html/errors_close.html. - Mobile template directory:
mobile/The internal structure is consistent as well.
Moreover, Anqi CMS also provides flexible custom template functionality.For document details, category pages, single pages, and so on, in addition to the above default naming, it also supports adding other custom filenames.For example, if the 'About Us' single page needs a unique display template, it can be namedpage/about.htmland specify this custom template when creating pages in the background. This flexibility allows operation personnel to implement highly personalized designs for specific content.
Adhere to these conventions and recommended directory structure, which can not only improve the organization and maintainability of template code, but also make team collaboration smoother and lay a solid foundation for the long-term operation of the website.
Frequently Asked Questions (FAQ)
1. What are the characteristics of AnQi CMS template engine, and what basic knowledge is needed to create templates?
The AnQi CMS is developed using Go language, its template engine syntax is similar to Django templates, easy to learn. Making templates usually requires mastering HTML, CSS, and JavaScript frontend basic technologies, as well as being familiar with Django style template syntax, including variable output ({{变量}}), conditional judgments ({% if %})、looping over({% for %}) and more. The system also has a wealth of tags and filters for calling system data, making logical judgments, and data formatting. Proficiently using these is the key to efficient template creation.
How to implement multilingual content display and switching functions for AnQi CMS website?
AnQi CMS is built with multilingual support, which is also reflected at the template level.First, configure the website's default language package in the global settings of the background.Next, create in the template directorylocalesDirectory, and create subdirectories according to language codes (such asen-us/zh-cn) and subdirectories as well.default.ymlDefine translation content in language files. In the template, you can use{% tr "键名" %}tags to call the corresponding translation text. In addition, the system provides{% languages websites %}The tag can retrieve the list of all multilingual sites, making it convenient to implement language switching functions on the front end and generate hreflang tags, which helps with search engine optimization and global content promotion.
3. How should static resources (such as images, CSS, JS) be managed and referenced in Anqi CMS to ensure the correct loading of templates?
In Anqi CMS, static resources should be stored uniformly in/public/static/In the directory. Template files reference these static resources through system tags to ensure the correctness of the path and the stability of the website. For example, you can use{% system with name="TemplateUrl" %}Label to get the static file address of the current template, and then combine it with the relative path to refer to CSS or JS files, such as<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">The benefit of doing this is that even if the website deployment environment or domain name changes, the static resource reference path can automatically adapt without manually modifying the template code.At the same time, image resources can also be uploaded and categorized through the background image resource management function, and referenced in the template through the corresponding document details or category details tags.