In Anqi CMS, flexibly controlling the display methods of different content models (such as articles, products, cases, etc.) on the front end of the website is the key to improving user experience and meeting diverse business needs.The system provides a powerful and easy-to-understand mechanism that allows you to finely design and manage the presentation effects of pages according to content type and specific needs.
Understanding the basic role of content models
Implementing front-end diversity through templates
The AnQi CMS adopts a template engine similar to Django, allowing you to fully control the layout and content display of pages through HTML files and specific tag syntax.
Model-level template customization:The system has set up default display templates for each content model. For example, all articles usually use
article/detail.htmlas the detail page template, and all products will useproduct/detail.htmlSimilarly, there is a corresponding list page.{模型table}/list.html.These are general templates at the model level, providing a unified display framework for all content under this model.You can edit these default templates to set the overall visual style for your articles or products.Categorization level template refinement:When you want different display styles for different categories under the same model, the Anqi CMS provides the category template feature.When editing a category, you can specify a "category template" (for the list page of the category) and/or a "document template" (for all content detail pages under the category).For example, articles under the "News and Information" category can use a different detail template than articles under the "Technical Articles" category.Further, you can also choose to apply the settings of the category template to all its subcategories, thus simplifying management.
Single document template coverage:For certain special, content pieces that require unique display effects, the system also provides ultimate flexibility.When publishing or editing a specific document (whether it's an article or a product), you can specify a "document template" for it separately.This template will take precedence over model and category level templates, ensuring that this document is presented in the way you specified.This is very useful when it is necessary to highlight a certain important product or to publish a special announcement.
Use custom fields to control display:The core of personalized display lies in how to effectively utilize the custom fields defined in the content model.For example, a 'product' model may include fields such as 'product size', 'material', and 'target audience', while an 'article' model may include fields such as 'reading time' and 'recommendation level'.These field values can be directly called in the template and judged by their content, thereby realizing dynamic page layout.For example, if a product has a promotional price, the template can determine whether the "Promotional Price" field exists and decide whether to display the "Original Price" with a strike-through.
Precisely call and render content in the template:
In the actual template file, you will use various template tags and filters provided by the Anqi CMS to obtain and process content data:
Get content details:Use
archiveDetailThe label can obtain detailed information about the current page or specified ID content, including title, body, thumbnail, and most importantly - various custom fields. For example,{% archiveDetail with name="Title" %}It will display the current document's title,{% archiveDetail with name="price" %}it may show the product price (if your product model has),pricethis custom field).Traverse custom parameters:For complex custom fields in the content model (such as multi-select, dropdown selection), or when you need to iterate through all custom fields to dynamically generate tables or lists,
archiveParamsLabels are particularly important. It can retrieve all custom parameters of the specified document and allows you to access them.forLoop through and display their names and values one by one.Display content list:
archiveListTags are a powerful tool for building list pages. They support content lists retrieved by various conditions such as model, category, recommended attributes, sorting method, and can be combined with pagination tagspaginationImplement a comprehensive list display function.Logic control and data processing:
ifTags are used for conditional judgment, such as determining whether to display based on whether a custom field has a value.forLabels are used for iterating over lists or arrays. Don't forget various practical filters, such assafefor safe HTML content output,thumbfor getting image thumbnails,stampToDateUsed for formatting timestamps, as well asrenderUsed for rendering Markdown content into HTML, all of which can help you better format and present data.
Through the multi-level template configuration and powerful template tag functions, Anqi CMS ensures that you can create unique and highly customized frontend display effects according to any content model, category, or the specific needs of individual articles.
Common Questions (FAQ)
问:How should I operate to set different list page layouts for the "手机" category and the "电脑" category under the "产品" model?答:You can edit the categories "Mobile" and "Computer" under "Content Management" -> "Document Categories" in the background. In the category editing interface, find the "Category Template" option and specify different template files for them, for example,
product/list-phone.htmlandproduct/list-computer.html. Thus, when users access these categories, the system will load the corresponding templates to render the list pages.问:My 'article' model has a custom field called 'recommendation index', and a 'hot recommendation' indicator will be displayed below the title on the article detail page only when the recommendation index is greater than 5. Can this be achieved?答:Absolutely. First, make sure that you have set up a custom field of numeric type called 'Recommendation Index' in your 'Article' model. Then, in your article detail template (such as
article/detail.html), you can usearchiveDetailTag fetches the value of this field and combinesifLogical judgment to control display. The basic code will look something like this:{% archiveDetail recommendIndex with name="推荐指数" %}Then,{% if recommendIndex > 5 %}<span>热门推荐</span>{% endif %}.问:I have created a content model named 'Service' and added content, but when accessing the front-end page, it displays a blank page or an error. How should I troubleshoot it?答:This is usually due to the lack of the corresponding model-level template file.When you create a new content model, you need to create the default detail page and list page template files for it.
service,pleasetemplatedirectory createservice/detail.htmlandservice/list.htmlFile, and ensure that these files contain the basic call tags of the model.If there are still issues, check whether the URL rules for the new model are correctly configured in the 'URL Rewrite Rules' on the backend.