In website operation, we always encounter some unique content, which may represent a special promotional activity, an important corporate report, or a page that needs to be presented specially.This content often does not meet the unified default style of the website, and needs its own 'face' to attract users and highlight the key points.AnQiCMS (AnQiCMS) understands this need and therefore provides a very flexible template customization feature, allowing us to easily set independent templates for specific articles, categories, or single pages, thus achieving customized content display.
Why do you need an independent template?
Imagine that most of the content on your website is regular articles, and a simple template is enough to display them.But suddenly, you need to publish an annual report, which may contain a large number of charts and videos, and requires a wider and more interactive layout;Or do you want to create a dedicated introduction page for a product series, with an entirely different layout, button, and image display style from the ordinary product detail page.For example, "About Us" or "Contact Us" pages of this kind, their content and structure are fixed, often requiring a unique brand display style.
In this case, if only the default template can be used, the website content will seem monotonous and will not highlight the value of specific information.The independent template function of AnQi CMS is specifically designed to solve this pain point, so that every piece of content can be presented to visitors in the most suitable way.
The basic storage and naming rules of template files
All template files are stored in the root directory of Anqi CMS/templateIn the folder. Each set of templates has its own subdirectory, for exampledefaultThe template is located in/template/default. The custom template file you create is usually also named with.htmlsuffix.
The AnqiCMS template engine supports Django template engine syntax, which is very easy to use. It also provides some default naming conventions based on content ID or category ID, which is itself a convenient way to customize:
- Document (article/product) detail page:You can create a name called
{模型table}/{文档id}.htmltemplate, for examplearticle/123.html, the system will automatically recognize and apply it to the article with ID 123. - Category list page:can create
{模型table}/list-{分类id}.htmlOf the template, for exampleproduct/list-45.htmlThis product category list page with ID 45 will automatically use this template. - Single page detail page:Similarly,
page/{单页面id}.htmlSuch a naming, such aspage/7.htmlCan automatically customize the single page with ID 7.
In addition to these automatically recognized naming methods, you can also customize more descriptive template filenames as needed, for examplearticle/special_event.htmlorpage/about_us.html. Let's see how to associate these custom templates with your content in the background.
Apply an independent template to specific content in the background.
The AnQi CMS backend interface design is intuitive, and it is very convenient to associate custom templates with content.You only need to find the corresponding 'template' setting item when editing the corresponding article, category, or single page and fill in the name of the template file you have prepared.
1. Set an independent template for a specific article (or product)
When you need a specific article (or product detail page) to have a unique display style:
- First, create the corresponding template file in your template directory, for example
article/annual_report.html. - Then, log in to the Anqi CMS backend, go toContent Management, selectPublish documentoredit documents.
- Find at the bottom of the editing page,.and expand the collapsible area.
- You will see a field namedDocument TemplateThe input box. Here, enter the custom template filename, for example
annual_report.htmlPlease note that you only need to enter the filename, not include/article/Such a model directory prefix, the system will automatically recognize. - After saving, the detail page of this document will use the one you specified.
annual_report.htmlThe template will be displayed.
2. Set an independent template for a specific category.
If you want all the content under a certain category (including the category list page and the article detail page of that category) to have a unified custom style, you can set it at the category level:
- Similarly, first create the custom template file, for example, for the list page
category/promo_list.htmlas well as the article detail page under the categoryarticle/promo_detail.html. - Log in to the AnQi CMS backend, go toContent Management, selectDocument Category.
- Select the category you need to customize, clickEdit.
- On the editing page,.you will see two important template settings:
- Category template:This is used to customize the current category list page. For example, you can fill in
promo_list.html. - Document template:This is used to customize the detail page of all articles (or products) under the current category. For example, you can fill in
promo_detail.html.
- Category template:This is used to customize the current category list page. For example, you can fill in
- There is anotherApply to subcategoryThe option. If you want this setting to also apply to all subcategories of the current category, remember to check it.
- After saving the changes, the display of this category and its (if checked) subcategory content will be according to your settings.
3. Set an independent template for a specific single page.
For independent single pages such as "About Us", "Service Introduction", etc., the steps to customize the template are similar to those for articles, and are very straightforward:
- First, prepare your single-page template file, such as
page/contact_us.html. - Log in to the AnQi CMS backend, go toPage Resources, selectPage Management.
- Select the single-page you need to customize and clickEdit.
- Find at the bottom of the editing page,Single page templateInput box.
- Enter the custom template filename you want, for example
contact_us.html. - After saving, this single page will be displayed in the exclusive style you designed.
Content displayed in the custom template.
Once you have set up an independent template for specific content, you can fully utilize the powerful Django template engine syntax and built-in tags of Anqi CMS in these template files to build the content. Whether it is the article detail page of{% archiveDetail %}Tags to get the content of the article and custom fields, or the category list page's{% archiveList %}Tags to loop through the article list, or in a single page's{% pageDetail %}Labels, these can help you flexibly display the required data, achieving truly customized content presentation. You can also combine conditional judgment{% if %}Loop traversal, such as{% for %}and various filters, making the logic and display of the template more rich.
In this way, Anqi CMS not only provides a stable and efficient content management foundation, but also gives us the ability to give more vitality and unique charm to the website content.Say goodbye to the same old, start customizing your exclusive template!
Frequently Asked Questions (FAQ)
1. What will happen to the website if the custom template file I specify for articles/categories/singles pages does not exist?If the specified template file does not exist, the system will not be able to find the corresponding template to render the page, which usually leads to the page displaying errors or being inaccessible. Therefore, be sure to ensure that the corresponding template exists before filling in a custom template name in the background..htmlThe file has been created correctly and placed in the template directory.
2. What is the difference between 'Category Template' and 'Document Template' in the category template?'Category Template' is used to define the category.list pageThe display style, such as the news list page you accessyourdomain.com/category/newswhen you see. 'Document template' is used to define the category belowdetails page for all articles (or products)The display style, such as the content you see after clicking on a news item in the news listyourdomain.com/article/news-item-1Page. By setting these two options, you can control the display of the category list and the specific content within the list.
3. What security CMS features can I use in a custom template to dynamically display content?You can fully utilize the powerful template tags and filters of Anqi CMS in your custom template. For example, use `{%