In AnQi CMS, when you want a specific article, product, category, or independent page to have a unique display effect, the system provides flexible template customization functions to easily achieve personalized content display.This is greatly beneficial for creating brand characteristics, launching special event pages, optimizing the user experience of specific content, and even improving SEO performance.
Why do you need to customize a template for specific content?
Imagine that your website has a \Traditional websites may require developers to modify the core code, but in AnQiCMS, you can easily meet these needs through custom templates.
Custom templates can help you:
- Highlight the key points of the content:Provide a dedicated layout for important articles or product designs to attract user attention.
- Optimizing user experience: Offer the most suitable reading or browsing experience based on the type of content.
- Strengthen brand image:Use unique visual elements and interactive methods for a specific theme.
- Improve SEO effectiveness:Flexibly adjust the page structure to better meet the crawling and ranking needs of search engines.
- Bear special functions: For example, provide a dedicated download link area for a download page, or provide a registration form for an event page, etc.
AnQi CMS template system overview
The template files of AnQi CMS are stored in/templatethe directory, each template package has its own independent directory, for example/template/default/. Template files are usually named.htmlSuffix, and written in a syntax similar to the Django template engine, which allows those familiar with front-end development to quickly get started. You will use double curly braces{{变量}}Output data, as well as single curly braces with a percentage sign{% 标签 %}To implement logical judgment, loop traversal, and other functions.
The system itself has provided a set of default template file naming rules, for example, the article detail page may bearticle/detail.html, the category list page might bearticle/list.htmlWhen you want to break these default rules and give special display to specific content, custom templates come into play.
How can you customize templates for specific documents or categories to achieve personalized display?
In Anqi CMS, specifying a custom template for specific content is a very intuitive process, mainly consisting of two core steps: first, prepare your template file, and then configure it simply in the background management interface.
First step: Prepare your custom template file
You need to create or modify a custom template based on the content type you want to customize (article, product, category, or single page) and your design requirements.htmlTemplate file.
Please specify the file location:Place your custom template file in the directory of the currently enabled template package. For example, if your template package is named
default, the path is usually/template/default/. To maintain the clarity of file management, it is recommended to create subdirectories based on content type, such as:- If it is a special article detail template, it can be placed in
template/default/article/special-doc.html. - If it is a list template of a specific category, it can be placed in
template/default/category/promo-list.html. - If it is a special single-page template, it can be placed in
template/default/page/about-us.html.
- If it is a special article detail template, it can be placed in
Write the template content:
- In the template file, you can write standard HTML, CSS, and JavaScript code.
- It is most important that you need to make use of the rich tags provided by Anqi CMS (such as
{% archiveDetail %}/{% categoryDetail %}/{% pageDetail %}etc.) to dynamically retrieve and display content data. For example, to display the article title, you can use<h1>{% archiveDetail with name="Title" %}</h1>. - can inherit
base.htmlThis skeleton template is used to maintain the unity of the website's overall style, only modifying the parts that need to be personalized.
Step two: specify the use of a custom template in the background.
After the template file is ready, the next step is to inform Anqi CMS which template to use when rendering specific content. This process varies slightly in the different content types in the backend management interface:
For a single document or product:
- Enter the backend“Content Management”-u003e“Publish document”or"Edit document".
- Find below the editing interface,“Other Parameters”Fold the area and expand.
- You will see a field named“Document Template”. Here, you need to enter the relative path and filename of your custom template file in the currently enabled template directory.
- For example, if your template file is
template/default/article/download.htmlthen you should fill inarticle/download.html. - The system will use the specified template here to render this specific document first.
- For example, if your template file is
For content categories:
- Enter the backend“Content Management”-u003e“Document Category”.
- Click the category next to the template you want to customizeEditbutton.
- Find below the editing interface,“Other Parameters”Fold the area and expand.
- FindCategory TemplateField. Similar to the document template, fill in the relative path and file name of the template file in the currently enabled template directory.
- For example, if your template file is
template/default/category/special-event.htmlthen you should fill incategory/special-event.html.
- For example, if your template file is
- Here is another.Whether to apply to subcategoriesThe option. If you check this option, all subcategories under this category (including their document lists) will inherit and use this custom template, greatly reducing repeated configuration.
For the independent single page:
- Enter the backend"Page Resources"-u003e“Page Management”.
- Click on the side of the single page you want to customizeEditbutton.
- Find below the editing interface,Single page templatefield. Enter the relative path and filename of the template file in the currently enabled template directory.
- For example, if your template file is
template/default/page/contact-us-v2.htmlthen you should fill inpage/contact-us-v2.html.
- For example, if your template file is
After configuration is complete, save your changes.When the user accesses the document, category, or single page you specify, Anqi CMS will automatically call the personalized template you carefully design, presenting a unique display effect.
Practical tips
- Clear template naming:Choose meaningful names for custom template files, such as
product/limited-edition.html, which will make it easier for you to find and manage in the future. - Make good use of built-in tags:The Anqi CMS provides a rich set of template tags for retrieving website settings, navigation, documents, categories, users, and other data.Make full use of these tags in your custom template, which can greatly reduce the need for manual content writing.
- Maintain consistency:Even though it is a custom template, try to maintain consistency with the overall brand style of the website, avoid too much difference in style between pages, which may affect user experience.
- Testing is crucial:Before the template is put into use, be sure to thoroughly test it on different devices and browsers to ensure that it displays normally and functions perfectly.
- Backup the template file: Before modifying the template, develop the habit of making backups to prevent unexpected situations.
By using the above method, you can fully utilize the flexible customization capabilities of Anqi CMS, allowing your website content to be presented in the most eye-catching way, truly realizing personalized content management and display.
Frequently Asked Questions (FAQ)
1. Where should I place the custom template file?You need to place the custom template file in the subdirectory of the currently enabled template directory. For example, if your template directory istemplate/defaultThen a custom article template can be placed intemplate/default/article/my-custom-template.htmlWhen specified in the background, you just need to fill inarticle/my-custom-template.html.
2. What will happen if the specified custom template file does not exist?If the background specified custom template file path is incorrect or the file does not exist, AnQi CMS will usually fall back to using its default universal template (for example, article details will usearticle/detail.htmlCategory list will be usedarticle/list.html), or in some cases, the page may fail to load correctly. Therefore, you must ensure that the specified template file is real and the path is correct.
**3. If a document specifies a custom template, and the category it belongs to also specifies a custom template,