As an experienced website operator proficient in AnQiCMS, I fully understand the importance of a flexible and powerful template system for displaying website content and enhancing user experience.AnqiCMS in template configuration and management provides high flexibility, able to meet various needs from personal blogs to enterprise-level multi-site operations.Below, I will elaborate on how to configure and manage multiple templates in AnqiCMS, to help you fully utilize this powerful feature.
Configuration and management of multiple templates in AnqiCMS
In AnqiCMS, templates are not just the appearance of the front-end page, but also the core of content display logic.The system allows you to easily configure and switch between multiple sets of templates and customize exclusive templates for specific content, thereby achieving personalized and differentiated operation of the website.
Understand the basic of AnqiCMS template
AnqiCMS template files are all.htmlsuffix, and are stored in the root directory of the system./templateIn the folder. Each independent template should have its own subdirectory under this directory. Similar to the Django template engine, AnqiCMS templates use double curly braces{{变量}}Output the variable, and use conditional judgment and loop control logic, etc.{% 标签 %}The form. Templates depend on CSS styles, JavaScript scripts, and images, etc., and it is recommended to store them separately./public/static/In the directory, to maintain the neat and structured directory structure.
AnqiCMS supports various template types, including adaptive (responsive) templates, code adaptation (providing different HTML for different devices) templates, as well as PC+mobile independent site modes. Especially in the latter two modes, you can create amobileSubdirectory for storing exclusive templates for mobile devices, achieving more refined device adaptation.
Template directory structure and configuration file
The core of each set of templates is/templateThe independent folder under the directory, as well as the folder within it.config.jsonThe configuration file. This file is the key to the system recognizing and managing templates.
config.jsonThe file contains basic information and usage status of the template, its typical structure is as follows:
{
"name": "默认模板",
"package": "default",
"version": "1.0",
"description": "系统默认模板",
"author": "kandaoni.com",
"homepage": "https://www.kandaoni.com",
"created": "2022-05-10 22:29:00",
"template_type": 0,
"status": 0
}
Among them,nameIt is the display name of the template,packageIt is the name of the template folder (must be English and numbers),template_typeDefined the template adaptation type(0For adaptive,1For code adaptation,2For computer+phone), andstatusmeans the template usage status(0为未启用,1为使用中)。值得注意的是,在所有模板中,只能有一套模板的statusThe value is1,即同时只能有一套模板处于启用状态。
The organization of template files in the directory mainly has two types: folder organization mode and flat file organization mode. The folder organization mode usually stores files of different types of pages (such as home page, detail page, list page, single page, etc.) in corresponding subdirectories, for exampleindex/index.html/{模型table}/detail.htmlEnglish.index.html/{模型table}_detail.html)to distinguish. Regardless of which mode is used, the system supports predefined custom template names, such as the default document template can be{模型table}/{文档id}.html, which can be applied automatically without any additional settings in the background.
In AnqiCMS background management template
AnqiCMS backend provides an intuitive interface for managing your templates.You can access the "Template Design" menu to view the "Website Template Management" feature, where you can view all installed templates and perform corresponding management operations.
Activate and switch template:The activation and switching of the template mainly throughconfig.jsonin the filestatusfield to achieve. When you want to enable a template, you need to make sure that itsstatusset1,while other templates are being modifiedstatusset0. In the background template management interface, there are usually convenient buttons or options to perform this operation, and the system will handle it automaticallyconfig.jsonchanges.
Customize templates for specific content:One of the highlights of AnqiCMS is its powerful content model mechanism, which makes it extremely simple to apply dedicated templates for specific content.
- Category Template:Under the "Content Management" section, in the "Document Category" settings, each category can be configured with a "Category Template". You can specify a
list.htmltemplate files outside of it (for exampledownload.html)to display the list of articles under this category.Additionally, you can choose whether to let the subcategory inherit this template setting.The category settings also include an option for a "Document Template", which can be used to specify a uniform detail page template for all documents under this category. - Document template:When publishing or editing documents, in addition to selecting the category, you can also find the 'Document Template' field in 'Other Parameters'. Here, you can specify a completely independent detail page template for the current document, for example, for a specific download article.
download.html. - Single Page Template:For the "Page Resources
page/about.html.
Through these detailed settings, you can present a diverse visual style and functional layout for different parts of the website, greatly enhancing the professionalism and user experience of the website.
Template application in multi-site management
Template development and optimization tips
There are several key points to note when developing or modifying templates:
- Uniform coding:All template files must use UTF-8 encoding to avoid page garbled text issues.
- Resource reference:The static resources referenced in the template should use the system-provided
TemplateUrlTags, such as<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">Ensure the correctness of the resource path, especially when there are multiple sites or changes in the deployment environment. - Code reuse:Make full use of the AnqiCMS template engine's
include/extendsandmacroauxiliary tags.includeCan be used to introduce common code snippets (such as header, footer);extendsUsed to implement template inheritance, build master page and overwrite specific areas;macroThen you can define reusable code blocks, improving development efficiency and code neatness. - Static rules:When you use custom rewrite rules in
{filename}or{catname}When setting variables, make sure that the custom URL you set for the document, category, or single page is unique across the entire site to avoid page conflicts.
Through a deep understanding and flexible application of the AnqiCMS template system, you will be able to create highly customized, feature-rich websites, effectively attract and retain users, and help your content operation achieve success.
Common Questions and Answers (FAQ)
1. How do I switch the template used by the current website in the AnqiCMS backend?答:You can find the 'Website Template Management' feature by accessing the 'Template Design' menu in the AnqiCMS backend.In this interface, all installed templates will usually be listed.You just need to select the template you want to activate, then click the corresponding 'Enable' or 'Set as Default Template' button, and the system will automatically update the configuration to switch to the template currently in use on the website.Please ensure that only one template is enabled at a time.
2. Can I use different template layouts for different pages of the website (such as news detail pages and product detail pages)?答:完全可以。AnqiCMS provides powerful content models and custom template features.You can set different document templates for different categories (such as 'News Category' and 'Product Category') under the 'Content Management' -> 'Document Classification' settings.Moreover, you can also find the 'Document Template' or 'Single Page Template' field in the respective editing interfaces when publishing or editing a single document or a single page, to specify an independent template file for specific content, achieving finer-grained layout control.
3. What if the website front-end does not take effect immediately after I modify the template file?答:通常情况下,EnglishCMS对模板文件的修改会实时生效。If the front-end page does not update, please first try to clear the browser cache, as the browser may cache old page resources.If the problem still exists, you can try to access the 'Update Cache' feature in the AnqiCMS backend, manually clear the system cache to ensure that the latest template files are loaded.In rare cases, if your website uses CDN, you also need to check and refresh the CDN cache.