As a senior CMS website operation personnel, I am well aware that a highly efficient and standardized template system is crucial for the long-term development of the website and the efficiency of content management.Auto CMS provides great convenience for content creators and operators with its simple and efficient architecture and Django-style template engine.During the template creation process, adhering to certain basic conventions and recommended directory structures can effectively improve development efficiency, reduce maintenance costs, and ensure flexible display of website content.
Basic conventions for AnQiCMS template creation
The template creation of Anqi CMS follows a series of basic conventions, aiming to ensure the consistency, maintainability, and system compatibility of template files.
Firstly, all template files uniformly use.htmlAs a file extension, and stored in the root directory of the website./templateTemplate folder.This makes it easier for the system to identify and load, and also makes the management of template files more organized./public/static/Directory, to achieve separation of static and dynamic, optimize loading performance.
On the template syntax level, Anqi CMS adopts a label marking method similar to 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 use single curly braces and percent signs.{% 标签 %}Define it. It should be noted that all logical tags must appear in pairs and be terminated with the corresponding end tag, for example{% if archive.Id == 10 %}这是文档ID为10的文档{% endif %}to ensure the integrity of the logical block.
The naming convention of variables is also very important. Anqi CMS recommends using camelCase naming convention, that is, the first letter of each word is capitalized, for examplearchive.Idandarchive.TitleBut some special variables specified by the system are excepted. Adhering to this naming convention helps to improve code readability and reduce potential errors.
To avoid page garbled characters issues, all template files must be unified to use UTF-8 encoding format.For users editing templates under Windows environment, make sure to select UTF-8 encoding when saving.
The template system of AnQi CMS supports various website modes, including adaptive template types, code-adaptive template types, and independent site modes for PC + mobile devices. If code-adaptive or PC + mobile device modes are chosen, separate templates need to be created for mobile devices, which should be stored in the main template directory.mobileIn the subdirectory, its internal structure is consistent with the PC template.
System also supports some default custom template names.If the template files are created in a specific format, the system can automatically apply them even without separate settings in the background.{模型table}/{文档id}.htmlThe default format of the document list can be{模型table}/list-{分类id}.htmlAnd the default format of a single page can bepage/{单页面id}.htmlThis mechanism provides more detailed template control capabilities for specific content.
Recommended directory structure for Anqi CMS template creation
The standard directory structure is the foundation for template development and maintenance. The root directory of the Anqi CMS template is/templateEach set of templates needs to create its own independent directory under this directory.
In each template directory, there must be oneconfig.jsonConfiguration file, used to describe the basic information of the template. This file plays the role of the 'ID card' of the template, 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(Template folder name, 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) andstatus(Template usage status, 0 for not enabled, 1 for 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 flat file organization mode.
InFolder organization modeBelow, template files will be grouped into different subdirectories according to functionality or page type, forming a hierarchical structure. For example:
- Public code files:
bash.html,用于存放页头、页脚等每个页面都可能继承的部分。 - Code snippet directory:
partial/,用于存放侧边栏、面包屑等可复用的代码片段。 - Home Page:
index/index.html. - Model Home Page:
{模型table}/index.htmlsuch asarticle/index.html. - Document details page:
{模型table}/detail.html,也可以为特定文档定制{模型table}/detail-{文档ID}.html. - Document List Page:
{模型table}/list.html,or for a specific category.{模型table}/list-{文档分类ID}.html. - Comment list page:
comment/list.html. - Online message page:
guestbook/index.html. - Single Page Detail Page:
page/detail.html,or for a specific single page.page/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/Its internal structure is consistent with the PC template.
whileFlat file organization modeMost template files are placed directly in the template root directory, and different page types are distinguished by file names. For example:
- Public code filesandCode snippet directoryThe same as folder mode.
- Home Page:
index.html. - Model Home Page:
{模型table}_index.html. - Document details page:
{模型table}_detail.html. - Document List Page:
{模型table}_list.html. - Comment list page:
comment_list.html. - Online message page:
guestbook.html. - Single Page Detail Page:
page.html,or for a specific single page.page-{单页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, the Anqi CMS also provides flexible custom template functionality.For document details, category pages, and single pages, in addition to the above default naming, it also supports adding other custom filenames.page/about.html, and specify this custom template when creating pages in the background. This flexibility allows operations personnel to implement highly personalized designs for specific content.
Adhere to these conventions and recommended directory structures, which can not only improve the organization and maintainability of template code, but also make team collaboration smoother, laying a solid foundation for the long-term operation of the website.
Common Questions and Answers (FAQ)
1. What are the features of the template engine of Anqi CMS, 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, making it easy to learn. Creating templates usually requires a grasp of front-end basic technologies such as HTML, CSS, and JavaScript, as well as familiarity with Django-style template syntax, including variable output ({{变量}})、Condition Judgment({% if %}), loop traversal ({% for %})etc. The system also has built-in rich tags and filters for calling system data, performing logical judgments, and data formatting. Proficiently using these is the key to efficient template creation.
2. How to implement multi-language content display and switching function for the Anqi CMS website?
The AutoCMS is integrated with multilingual support, which is also reflected in the template level.Firstly, configure the default language package of the website in the global settings on the back end.localesTable of contents, and create subdirectories in it according to language codes (such asen-us/zh-cn) and create subdirectories.default.ymlEnglish language files to define translation content. In the template, you can use{% tr "键名" %}tags to call the corresponding translation text. Additionally, the system provides{% languages websites %}Label, which can obtain the list of all multilingual sites, convenient for implementing language switching functions and generating hreflang tags on the front-end, and helps with search engine optimization and global content promotion.
3. How should static resources (such as images, CSS, JS) be managed and referenced in Safe CMS to ensure the correct loading of templates?
In the AnQi CMS, static resources should be stored uniformly in/public/static/The template files refer to 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 retrieves the static file address of the current template and then combines it with the relative path to reference CSS or JS files, such as<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">.The advantages of doing this are that even if the website deployment environment or domain name changes, the static resource reference paths can automatically adapt without manual modification of the template code.At the same time, image resources can also be uploaded and categorized through the image resource management function on the backend, and referenced in the template through the corresponding document details or category details tags.