Hello, as a senior operation personnel of AnQiCMS, I am very happy to elaborate on how to customize the directory structure and file naming rules of AnQiCMS templates in detail.Understanding these basics is the key to efficient management and optimization of website content.
Custom Overview of AnQiCMS Templates
AnQiCMS is an enterprise-level content management system based on Go language, which provides high flexibility in template customization.It uses syntax similar to the Django template engine, making it easy for frontend developers to get started.To ensure the effective display and management of website content, a clear and standardized template directory structure and file naming rules are crucial.This not only helps with team collaboration and post-maintenance, but also better supports SEO optimization and multi-language deployment./templateUnder the root directory.
Establishing the root directory and configuration file of the template
Each customized template needs to be in/templateA folder is present in the directory, the name of which usually represents your template package name. Inside this template folder, there must be aconfig.jsonConfiguration file. This file is the key to AnQiCMS identifying and managing your templates, it contains basic metadata and type settings.
config.jsonFiles allow you to define a series of fields, although most of them are optional, but a reasonable configuration can provide a better template management experience. For example,"name"fields are used to specify the display name of the template,"package"The field should match the name of your template folder, and only supports letters and numbers."version"and"description"The fields are used to record the version information and feature description of the template."author"and"homepage"It indicates the author of the template and their website."created"Records the creation time of the template."template_type"The field is the key to defining the response mode of the template, which has three optional values:0Represents an adaptive template,1Represents code adaptation template,2indicating independent templates for PC and mobile endpoints."status"field is used to indicate the enable status of the template,0is disabled,1In use, it is noted that only one template can be used in all installed templatesstatusThe value of1.
Template file structure and naming rules
AnQiCMS template files are unified in use.htmlAs a suffix, and the file content should be encoded in UTF8 to avoid garbled characters.When organizing template files, AnQiCMS provides two main modes: folder organization mode and flat file organization mode, you can choose one according to the project complexity and personal preference.
Folder organization mode
In this mode, template files are organized into subfolders to classify, making the structure clearer.
- Public code snippets:Commonly, headers, footers, and other publicly inherited parts are named
bash.html. Other reusable code snippets like sidebars, breadcrumbs, etc. are stored inpartial/the catalog, for examplepartial/sidebar.html. - Home:The homepage template of the website is usually named
index/index.html. - Pages related to the model:AnQiCMS supports a flexible content model. For different content models (such as articles, products), you can create folders named after the model table and define model-related pages within them:
- Model Home:
{模型table}/index.html - Document Details Page:
{模型table}/detail.html.For documents that require special customization, you can also use{模型table}/detail-{文档ID}.htmlnaming conventions. - Document List Page:
{模型table}/list.html. Use for specific category lists{模型table}/list-{文档分类ID}.html.
- Model Home:
- Comment list page:
comment/list.html. - Online message page:
guestbook/index.html. - Single page detail page:
page/detail.html. Use for specific single pagespage/detail-{单页ID}.html. - Search Page:
search/index.html. - Tag-related Page:
- Tag Homepage:
tag/index.html. - Tag Document List Page:
tag/list.html.
- Tag Homepage:
- Error Page and Site Status Page:
- 404 Error Page:
errors/404.html. - 500 Error Page:
errors/500.html. - Site Closure Prompt Page:
errors/close.html.
- 404 Error Page:
- Mobile Template:If
config.jsonintemplate_typeSet to code adaptation or PC+mobile mode, you need to create one under the template root directorymobile/Subdirectory, and create mobile template files in accordance with the structure and naming rules of the PC template.
Flat file organization mode
For structures that are relatively simple or prefer centralized file management of templates, the flattened file organization pattern can be used, placing all template files directly under the template root directory and distinguishing page types by file name prefixes.
- Public code snippets:The folder mode is the same,
bash.htmlandpartial/The directory remains unchanged. - Home:
index.html. - Pages related to the model:
- Model Home:
{模型table}_index.html. - Document Details Page:
{模型table}_detail.html. - Document List Page:
{模型table}_list.html.
- Model Home:
- Comment list page:
comment_list.html. - Online message page:
guestbook.html. - Single page detail page:
page.html. Use for specific single pagespage-{单页ID}.html. - Search Page:
search.html. - Tag-related Page:
- Tag Homepage:
tag_index.html. - Tag Document List Page:
tag_list.html.
- Tag Homepage:
- Error Page and Site Status Page:
- 404 Error Page:
errors_404.html. - 500 Error Page:
errors_500.html. - Site Closure Prompt Page:
errors_close.html.
- 404 Error Page:
- Mobile Template:
mobile/The directory structure and file naming rules are consistent with the PC end.
Custom template file naming
In addition to the above default and model-related naming rules, AnQiCMS also supports more fine-grained custom template naming.This means you can create a completely independent template file for a single document, category, or page.page/Create one under the directoryabout.htmlFile, then set up the single-page call in the backgroundabout.htmlAs its exclusive template. This greatly enhances the flexibility of content display
Syntax and variable calls in the template
AnQiCMS's template engine supports a tag marking method similar to Django. Variable output uses double curly braces{{变量}}For example{{archive.Title}}Display the article title. Control structures (such as conditional judgments and loops) use single curly braces and the percent sign.{% 标签 %}And it needs clear end tags, such as.{% if 条件 %} ... {% endif %}. Variable names usually follow camel case naming conventions for easy identification and use.
Management of static resource files.
The style files (CSS), JavaScript scripts, and images, etc., used in the template should be stored independently in/public/static/Directory. This can be separated from the template file, making it easier to manage, and can be optimized in conjunction with CDN services to improve website loading speed.
By following these directory structures and file naming conventions, you will be able to build a clear, easy to maintain, and powerful AnQiCMS website template, thereby providing your readers with an excellent content experience.
Frequently Asked Questions (FAQ)
Ask: I have created the template file according to the document, but it does not display on the website front-end. How should I investigate the problem?
Answer: First, please confirm whether the template folder contains the correctconfig.jsonFile and its"status"field is set to1
Question: Why is my custom template not automatically applied, for example, I createdarticle/detail-10.html, but the article with document ID 10 still usesarticle/detail.html?
Answer: AnQiCMS has a search order when parsing templates. Although{模型table}/detail-{文档ID}.htmlThis specific ID template usually has a higher priority, but it still needs to be ensured that the template file exists and the content is correct.If it was not applied automatically, please check if the file has syntax errors that cause parsing to fail, or if other templates were manually specified in the background document editing interface.In some cases, manually specifying a template will override the default matching rules.config.jsonof"template_type"whether it matches your website model and whether the related cache has been cleared.
Ask: Where should I place external JavaScript libraries or CSS frameworks if I use them in the template file?
Answer: Any external or custom JavaScript scripts, CSS style sheets, and images, etc., should be stored in the AnQiCMS./public/static/Under the directory. For example, you can create/public/static/css/Store CSS files, `/public/static/js`}]