In website operation, we often encounter such needs: different types of content, even on the same website, need to have completely different display styles.For example, a product detail page of an e-commerce website needs to highlight product images, prices, inventory information, etc., while the blog article detail page may focus more on the reading experience, author information, and publication date.This ability to customize the style of detail pages based on content type (or content model) is crucial for improving user experience and content professionalism.
Can we achieve such a fine-grained content model matching with the detail page style when using AnQiCMS?The answer is affirmative, and AnQiCMS is very flexible and powerful in this aspect.
The powerful foundation of content models
One of the core strengths of AnQiCMS is its 'flexible content model' feature.The system includes common content types such as 'Article Model' and 'Product Model', and it also allows users to completely customize new content models according to their business needs.For example, you can create a "case model" to showcase company projects, or a "campaign model" to publish marketing promotion content.
Each custom content model is not just a name; it also defines the unique fields of this type of content.For example, a product model can have fields such as "price", "inventory", "brand", etc., while an article model may have fields such as "author", "source", "recommendation level" etc.These customized fields are the foundation for differentiated detail page styles, as they determine which data can be called and displayed in the template.
The core mechanism of customizing the detail page style
The key to AnQiCMS displaying different detail page styles for different content models lies in its intuitive and powerful template naming conventions. In the root directory of AnQiCMS templates (/templateUnderneath, we can create a dedicated folder for each content model and place the corresponding detail page template files in these folders.
In particular, the system will search for the corresponding template based on the content's 'model table name'. For example:
- For content published through the 'Article Model', AnQiCMS will default to searching for the location of
/template/{你的模板目录}/article/detail.html. - And for content published through the 'Product Model', it will search for
/template/{你的模板目录}/product/detail.html.
This means that we just need to create corresponding folders for different content models (the folder names are usually consistent with the English table names of the models) and design their respectivedetail.htmlTemplates can allow articles to have their layout, products to have their style, and not affect each other.This convention is greater than configuration design, which greatly simplifies the process of template development, allowing us to focus on the design itself without the need for complex background association settings.
More granular control
AnQiCMS's flexibility is not limited to the model level. If we encounter a specific article, product, or page that needs a unique display under the same content model, it also provides a solution.
When editing a single document (such as an article or product) in the background, we will find a 'Document Template' setting option. Here, we can specify a separate template file for this particular document, for examplecustom_article_detail.html. The system will use this specified template first, covering the default detail page style of the content model it belongs to, thereby meeting the need for more personalized display.
This flexible customization capability also extends to category pages and single pages:
- Category template:We can set a dedicated list page template for a specific category (for example
{模型table}/list-{分类ID}.html),Let the content lists of different categories present different styles. - Single page template: For pages such as "About Us", "Contact Us", etc., independent template files can also be specified when editing in the background (for example,
page/about.htmlMake sure that these special pages also have a customized appearance.
Dynamic presentation of template content
How do we dynamically load and display content in the dedicated detail page templates designed for different content models?The AnQiCMS template tag system (using Django template engine syntax) provides powerful support.
ByarchiveDetailTags, we can easily obtain all standard field information of the current document, such as the title (Title), content (Content),release time(CreatedTime)Etc. What is even more surprising is that the custom fields defined in the content model, such as 'price' and 'stock' in the product model, or 'article source' in the article model, can be directly displayed in the corresponding detail page template through simple tag calls.This means that your product detail page can easily display the various parameters of the product, as well as the article details