As an experienced AnQiCMS website operator, I am well aware of the importance of a flexible and powerful template system for displaying website content and improving user experience.AnqiCMS provides high flexibility in template configuration and management, meeting the 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, helping you make full use of this powerful feature.
Configure and manage 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 AnqiCMS template
AnqiCMS template files are all with.htmlsuffix, and are uniformly stored in the root directory of the system./templateIn the folder. Each independent template should have its own subdirectory in this directory. Similar to the Django template engine, AnqiCMS templates use double curly braces{{变量}}output variables, while logical operations such as conditional judgments and loop control are used{% 标签 %}The form. The CSS styles, JavaScript scripts, and static resources such as images that the template depends on should be stored separately./public/static/In the directory, to maintain the neat and structured template directory.
AnqiCMS supports various template types, including adaptive (responsive) templates, code adaptation (providing different HTML for different devices) templates, and PC + mobile independent site mode. Especially in the latter two modes, you can create a template within the template directory.mobileSubdirectory for storing dedicated mobile templates, achieving more refined device adaptation.
Template directory structure and configuration file
The core of each template is its/templatea standalone folder under the directory, as well as the folder withinconfig.jsonthe configuration file. This file is the key to the system's identification and management of 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,nameIs the display name of the template,packageIs the name of the template folder (must be English and numbers),template_typeDefined the template compatibility type(0For adaptive,1For code adaptation,2for computer+mobile phone), whereasstatusindicates the usage status of the template(0is disabled,1indicating it is in use). It is worth noting that among all templates, only one set of templatesstatusThe value of1That is, only one template can be enabled at a time.
There are mainly two ways to organize template files in a directory: folder organization mode and flattened file organization mode. The folder organization mode usually places 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.htmland. The flattened file organization pattern then places these files directly in the root directory of the template, through naming conventions (such asindex.html/{模型table}_detail.html)to distinguish. Regardless of the mode used, the system supports predefined custom template names, such as the default document template can be{模型table}/{文档id}.html, which can be automatically applied without any additional settings in the background.
On AnqiCMS backend management template
The AnqiCMS backend provides an intuitive interface to manage your templates.You can access the "Template Design" menu to access 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 templates mainly involves modifying theirconfig.jsonin the filestatusfields to enable a template. When you want to enable a certain template, make sure that itsstatusis set to1while enabling other templates'statusis set to0. In the background template management interface, there are usually convenient buttons or options to perform this operation, the system will automatically handle it.config.jsonfor modification.
Customize a template for specific content:AnqiCMS is a major highlight with its powerful content model mechanism, which makes it extremely easy to apply dedicated templates for specific content.
- Category template:In the 'Content Management' under the 'Document Category' settings, each category can be configured with a 'Category Template'. You can specify a
list.htmltemplate file outside of the examplesdownload.htmlTo display the list of articles under this category. In addition, you can also choose whether to inherit the template settings of the subcategory.There is also a 'Document Template' option in the category settings, which can specify a detail page template for all documents under this category. - Document template:When publishing or editing a document, 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' under 'Single Page', the 'Single Page Template' field is also provided, allowing you to specify customized template files for single pages such as 'About Us', 'Contact Us', etc., for example
page/about.html.
By 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
For operators with multiple site needs, the "Multi-site Management" feature of AnqiCMS is closely integrated with the template system.When adding a new site through Docker or Baota panel and other methods, the system will prompt you to 'select the template to use'.This means that each independent AnqiCMS site can choose and enable its own template, even different template types (adaptive, code adaptation, PC + mobile independent), thus easily achieving brand differentiation or meeting the needs of different business scenarios.
Template development and optimization hints
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 garbling issues.
- Resource reference:The static resources referenced in the template should use the provided by the system.
TemplateUrlLabel, for example<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">Ensure the correctness of the resource path, especially when there are changes in multi-site or deployment environments. - Code reuse:Fully utilize the AnqiCMS template engine's
include/extendsandmacroand other auxiliary tags.includeCan be used to introduce common code snippets (such as headers and footers);extendsUsed to implement template inheritance, build master pages, and overwrite specific areas;macroReusable code blocks can be defined to improve development efficiency and code neatness. - Static rules:When you use custom static rule in
{filename}or{catname}When using 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.
By deeply understanding and flexibly applying the AnqiCMS template system, you will be able to create highly customized, feature-rich websites, effectively attract and retain users, and help you achieve success in content operation.
Frequently Asked Questions (FAQ)
1. How can I switch the template used by the current website in the AnqiCMS backend?Answer: You can find the 'Website Template Management' feature by accessing the 'Template Design' menu in the AnqiCMS backend.In this interface, it usually lists all the installed templates.You just need to select the template you want to activate, then click the corresponding 'Enable' or 'Set as Main Template' button, and the system will automatically update the configuration to switch to the template currently used by the website.Make sure to enable only one template at a time.
2. Can I use different template layouts for different pages on the website (such as news detail pages and product detail pages)?Certainly, it can be done. AnqiCMS provides powerful content models and custom template functions.You can specify different document templates for different categories (such as 'news categories' and 'product categories') under the 'Content Management' 'Document Category' settings.In addition, when publishing or editing a single document or a single page, you can also find the "Document Template" or "Single Page Template" field in their respective editing interfaces, 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?Answer: Generally speaking, AnqiCMS will take effect in real time on the modification of template files.If you find that the front-end page is not updated, please try to clear the browser cache first, as the browser may cache old page resources.If the problem still exists, you can try to access the 'Update Cache' feature on the AnqiCMS backend, manually clean the system cache to ensure that the latest template files are loaded.In very few cases, if your website uses a CDN, you also need to check and refresh the CDN cache.