As a professional deeply familiar with the operation of Anqi CMS, I know the importance of content presentation in attracting and retaining users.The flexibility of AnQi CMS in content management, especially in template customization, provides us with a great degree of freedom, ensuring that every part of the content can be displayed in the most fitting way according to its characteristics.Today, I will elaborate on how to set up a custom template for a specific document category, and flexibly control whether the sub-categories inherit the template, thereby helping you create a more personalized and professional website.
Why do you need a custom category template?
In website operation, documents of different types often require different display layouts and styles.For example, a "news information" category may require a concise list of articles, highlighting the title and publication time;And a 'product case' category may need to display product images, feature summaries, etc., with a richer layout.The AnQi CMS custom category template feature is designed to meet such refined operation needs.It allows us to specify exclusive template files for specific categories, breaking the limitations of a single layout, improving user experience, even assisting SEO, and highlighting content points better through a unique page structure.
Set a custom template for a specific category
To apply custom templates to your documents, you need to first enter the Anqi CMS backend management interface.
First, please navigate to the "Content Management" section, and then click "Document Category".Here, you will see the list of all created categories. Select the target category you want to set a custom template for, and click the 'Edit' button next to it.
After entering the category editing page, please scroll down the page to find the "Other Parameters" section and expand it.You will see an input box named "Category Template" here.This input box is where you specify the custom template file.
Here, you need to enter the name of the template file you have designed. For example, if you have designed a list template for a category nameddownload.htmlyou can directly enter it here.download.html. The system will base on the content model of the category you have selected (such as "article model" or "product model"), in the corresponding model directory under your current theme template folder (such astemplate/your_theme_name/article/ortemplate/your_theme_name/product/Search and apply this custom template.
Make sure the template file you entered actually exists in your theme template directory.If the system cannot find the corresponding template file, the category page may not display normally, affecting user access.To avoid such problems, it is recommended to save and access the front desk page immediately after filling in.
Control the template inheritance behavior of subcategories
Below the 'Category Template' input box, you will see an option named 'Apply to Subcategories'.This option gives you great flexibility to decide the application scope of the custom template in the hierarchical structure.
By default, the Anqi CMS category template isNot inheritedThis applies to subcategories. This means that if you set a custom template for a parent category, its subcategories will continue to use their own template settings (which may be the default template or a custom template specified by each one).This default behavior is suitable for those scenarios where the content of parent-child categories is quite different and requires independent layouts.
However, if you want the custom template of a parent category to be applied to all its child categories, thus maintaining visual and functional consistency throughout the entire category hierarchy, you can set the 'Apply to child categories' option toInheritanceOnce inheritance is enabled, regardless of whether the child category has its own template settings, it will uniformly adopt the custom template specified by the parent category.This is very useful for cases that need to maintain strong brand consistency or a highly unified structure for sub-category content, which can greatly reduce the workload of repeated settings.
In actual operation, you need to decide whether to enable inheritance based on the overall design and content planning of the website.For example, if you have a 'download center' parent category and all its subcategories (such as 'software download', 'document download') share the same download list layout, enabling inheritance will be a wise choice.Conversely, if the subcategories have different focuses, such as 'News Reporting' and 'Special Research' which belong to the 'Articles' parent category, but have significantly different page layouts, then the default non-inheritance state should be maintained.
The practice of template file naming and storage
The default storage location of AnqiCMS template files:/templateUnder the root directory, each theme has its own folder, for example/template/your_theme_name/. Within the theme folder, you can create subdirectories according to the content model, such asarticle//product/,to better organize the template file.
For the category list page, the system will default to searching for{模型table}/list.htmlfile. When you enter a custom template name in the category settings, for exampledownload.htmlThe system will first look for the template path corresponding to the current modeldownload.html(such astemplate/your_theme_name/article/download.htmlYou can also use more descriptive filenames, for examplelist-download-center.htmlTo avoid confusion and improve maintainability.
By understanding and mastering the classification template customization and inheritance control features of Anqi CMS, you can manage the content presentation of your website more flexibly, providing your readers with a better and more personalized browsing experience.
Frequently Asked Questions (FAQ)
Q1: I have set a custom template for the category, but the front-end page shows an exception, how should I investigate?
A1:First, please confirm that the template filename you have entered in the classification template field is correct, and that the file indeed exists in the corresponding model subdirectory under the current theme template directory (for exampletemplate/your_theme_name/article/your_template_name.htmlIn addition, check for syntax errors in the template file content. Anqi CMS is based on the Django template engine, which has strict syntax. Even minor errors can cause the page to fail to parse.If the file path and content are correct, try clearing the website cache and check for error messages in the browser console.
Q2: In addition to the category list page, can I set a custom template for a single document or product?
A2:Yes, AnQi CMS supports setting custom templates for individual documents or products.When editing a document or product, you will see a "document template" or a similarly named field.Enter the template file name you designed, and the system will prioritize using this file to display the details page of this specific document.This is similar to the way the classification template is set up, providing finer control over content display.
Q3: Can I enable a different template for a specific child category if my parent category has enabled template inheritance?
A3:When the 'Apply to child categories' setting of the parent category is set to 'Inherit', child categories will be forced to use the parent category template.This means that you cannot directly override this inheritance through the "classification template" field of the subcategory.To meet your needs, you need to disable the template inheritance feature of the parent category and then set up a template separately for each child category that requires a custom template.Or, you can use logical judgment inside the parent category template (for example{% if category.Id == specific_subcategory_id %}To render different content blocks or include different sub-templates for specific subcategories.