How to customize the directory structure and file naming rules of AnQiCMS templates?

Calendar 👁️ 69

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 namedbash.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 namedindex/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.
  • 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.
  • 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.
  • Mobile Template:Ifconfig.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.
  • 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.
  • 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.
  • 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 to1It indicates that the template has been enabled. Next, check if the template file itself is encoded in UTF8, and if the filename and path strictly follow the above naming rules.A common mistake is a misspelled filename or mismatch in case.In addition, if it involves a specific model, category, or single-page template, you need to confirm that the corresponding page, category, or document has been specified to use the custom template you created.Finally, don't forget to clear the system cache and browser cache of AnQiCMS.

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`}]

Related articles

How to create a multi-level website navigation menu in AnQiCMS template?

As an experienced AnQiCMS website operations staff, I know that a clear and efficient multi-level website navigation menu is crucial for user experience and website SEO.AnQiCMS provides a comprehensive mechanism in template design and backend management, helping us easily build such a menu.I will elaborate in detail on how to create a multi-level website navigation menu in the AnQiCMS template.

2025-11-06

How to remove the blank lines that may be generated by logic tags in the AnQiCMS template?

As an experienced CMS website operation personnel of an enterprise, I know that every detail of content presentation is crucial, including seemingly trivial blank lines.In a meticulously constructed template, unnecessary blank lines not only affect the neatness of the HTML code, but may also cause unexpected visual problems in certain layouts.Today, let's delve into how to efficiently remove blank lines that may be generated by logical tags in the AnQiCMS template.

2025-11-06

How to dynamically display the home page banner list in AnQiCMS template?

As a senior who has been deeply engaged in AnQiCMS content operation for a long time, I know the importance of the homepage banner for the visual appeal and marketing promotion of the website.A well-designed and dynamic Banner list that can quickly attract visitors' attention and effectively convey the latest product, service, or event information.Today, I will demonstrate in detail how to dynamically display the Banner list on the website homepage based on the powerful template function of AnQiCMS.

2025-11-06

How to call the switch link of multi-language sites in AnQiCMS template?

As a senior CMS website operator for an enterprise security company, I know that the multilingual site switching link is crucial for expanding the international market and improving user experience.AnQi CMS provides us with a convenient and efficient solution with its powerful multi-site and multi-language support function.Below, I will elaborate on how to call the multilingual site switch link in the AnQiCMS template.Flexible construction of multi-language site switching function Anqi CMS has fully considered the needs of enterprises and operators in global layout from the beginning of its design, originally supporting multi-site management and multi-language content switching

2025-11-06

How to specify an independent template file for a specific category, article, or single page in AnQiCMS?

As a deep user of Anqi CMS website operators, I know that the flexibility of content display is crucial for attracting and retaining users.Strong support is provided by Anqicms in this aspect, allowing us to specify exclusive template files for specific categories, articles, even independent pages, thereby achieving highly customized content presentation.This not only helps to improve the user experience, but also provides great convenience for our refined operation and SEO optimization.

2025-11-06

How to get and display the global configuration information (such as name, Logo) of AnQiCMS template?

As an experienced website operator proficient in AnQiCMS, I know that efficiently and accurately obtaining and displaying the global configuration information of the website is crucial for website maintenance, brand consistency, and user experience.AnQiCMS provides intuitive and powerful template tags, making it easy to achieve this goal.In AnQiCMS template, obtain and display the global configuration information of the website, such as the website name, Logo, filing number, etc., mainly depending on the built-in `system` tag

2025-11-06

How to call and display the contact information (such as phone, email, social media) configured in the AnQiCMS template?

As a senior content worker who deeply understands the operation of Anqi CMS, I know the importance of displaying the contact information of the enterprise externally.This not only concerns whether customers can conveniently contact you, but also is the basis for building trust and promoting business cooperation.AnQi CMS provides a直观 and flexible solution for website operators, allowing you to easily manage and display various contact information without writing complex code.

2025-11-06

How to dynamically generate the SEO title, keywords, and description of the current page and support the website name suffix?

As an experienced content management expert who is deeply familiar with AnQiCMS operations, I know the importance of Search Engine Optimization (SEO) for website traffic and user retention.The website's SEO title, keywords, and description (usually abbreviated as TDK) are key factors for search engines to understand page content and for users to decide whether to click.AnQiCMS provides a powerful and flexible mechanism that allows us to dynamically generate these important SEO elements and conveniently integrate the website name as a suffix to enhance brand recognition.

2025-11-06