When operating a website, we often encounter such situations: different types of content, even articles in the same category or different 'About Us' pages on the same website, all hope to have a unique display style to better attract readers and convey information.AnQiCMS (AnQiCMS) fully understands this need and therefore provides a very flexible template customization mechanism, allowing us to easily customize the display style for specific categories or pages.
1. Understand the storage and naming conventions of template files
Before starting customization, we first need to know the location of the template files and some basic naming conventions. The template files of Anqi CMS are stored uniformly in/templateUnder the directory. Each template will have its own independent folder, such asdefault. In this folder, you can place all the related content for this template..htmlFiles, while styles (CSS), JavaScript scripts, and images, etc., static resources will be stored in/public/static/Directory.
The Anqi CMS template system is very intelligent, it supports various ways to identify and apply templates:
Universal default template:For articles, product lists, detail pages, single pages, etc., there is a universal default template. For example,
{模型table}/detail.htmlUsed for the detail pages of all articles or products,{模型table}/list.htmlFor all article or product list pages, whilepage/detail.htmlIt is the default template for all single pages. When no special template is specified, the system will automatically call these general templates.The convention template for binding ID or alias:If you want a specific document, category, or single page to have a unique style, you can name the template file using its ID or URL alias.
- ForDocument detail pageYou can create
{模型table}/{文档ID}.htmlThe template file, for examplearticle/123.htmlThe system will automatically apply this template when accessing the article with ID 123. - ForCategory list pageCan create
{模型table}/list-{分类ID}.htmlThe template format, for examplearticle/list-5.htmlWhen accessing the article category list with ID 5, this template will take effect. - Forsingle pageCan create
page/{单页面ID}.htmlThe template format, for examplepage/7.htmlThese conventions for naming make it unnecessary for you to make additional settings in the background, as the system can automatically recognize and apply them.
- ForDocument detail pageYou can create
Flexible templates with custom naming:In addition to the aforementioned agreements, AnQi CMS also provides the most flexible method - you can freely name the template files and then specify the use of this template in the corresponding content editing interface in the background. For example, you can create a template named
download-page.htmlThe template is specifically used for a special download page.
No matter which method you choose, make sure your template file uses UTF-8 encoding to avoid page garbled text. In addition, if your website needs to adapt to mobile devices, you can create a folder in the template directory.mobileSubdirectory, and copy the same template structure in it, the system will automatically call it on the mobile phonemobileThe template under the directory.
Second, associate the custom template in the background
After creating the template file, the next critical step is to inform the Anqi CMS which content should use which template.This process is very intuitive, usually you can find the corresponding options in the content editing interface.
Customize templates for articles or products:When you publish or edit a document (article or product) in the "Content ManagementHere, you can enter the filename of the template you wish to use for the document.
special_news.htmlA template, specifically used to display an important news article, just fill in herespecial_news.htmlJust do it.Custom template for categories:In the "Content Management" "Document Category" page, when editing a category, there is also a "Category Template" field in the "Other Parameters". Here you fill in the template filename (for example
product_list_promo.htmlCustom template for single page:In the "Page Resources" under "Page Management
about_us_fancy.htmlTemplate, fill in here.
When you specify a custom template in the background, Anqicms will prioritize and use the file you specified when rendering the corresponding page.If the file does not exist, the page will not be able to open normally, so please make sure that the path and name of the template file are correct.
Section 3: Tips for writing within the template.
In your custom template file, you can use tag syntax similar to Django to control content display. For example,{{变量名}}Used for output data, and{% 标签 %}which is used for logical control, such as,{% if 条件 %}to make judgments,{% for item in 列表 %}Perform a loop.
It is strongly recommended to make use of templates to improve maintainability and reusability.{% include "片段.html" %}and{% extends "基础模板.html" %}These tags.includeYou can include commonly used code snippets such as headers, footers, sidebars, etc. in your template to avoid repetition;extendsIt allows you to create a basic page skeleton (including common HTML structure, style references, etc.), and then let other pages inherit this skeleton, only rewriting the customized blocks.This way, changing the common part only requires changing one place, greatly improving efficiency.
By this means, the template customization function of Anqi CMS is like customizing a set of exclusive clothing for every corner of the website, allowing content to present in a proper scene with **posture.In order to enhance user experience, strengthen brand image, or optimize the SEO display of specific content, this flexible control capability can bring tangible convenience and value to the operation of your website.
Frequently Asked Questions (FAQ)
- Q: Where should I place my custom template file in the website directory?A: You should place the custom template file in
/template/您的模板目录/. For example, if your template directory isdefaultThen it can be placed in/template/default/. If you are customizing a template for a specific document, category, or single page, you can also follow the agreement (such asarticle/123.htmlor