In AnQi CMS, flexibly controlling the display methods of different content models (such as articles, products, cases, etc.) on the website's frontend 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 design and manage the display effects of the page in fine detail according to the content type and specific needs.

Understanding the basic role of content models

Firstly, we need to understand the core status of the content model in the Anqi CMS.The content model does not only define the structure of the content but also determines which data you can collect for different types of content.When you create or edit a content model, such as an 'article' model or a 'product' model, you can customize a series of fields, such as the 'author' or 'source' of an article, or the 'price', 'inventory', and 'color options' of a product.These custom fields are the foundation for displaying personalized content on the front end, and they will become the unique data you call and present in the template.These fields make "article" more than just a title and content, and also give "product" rich attribute details.

Implementing frontend display diversity through templates

The AnQi CMS uses a template engine similar to Django, allowing you to fully control the layout and content display of the page through HTML files and specific tag syntax.

  • Model-level template customization:The system has preset default display templates for each content model. For example, all articles will usually usearticle/detail.htmlAs the detail page template, all products will useproduct/detail.htmlSimilarly, the list page also has corresponding{模型table}/list.htmlThese are general templates at the model level, providing a unified display framework for all content under the model.You can edit these default templates to set the overall visual style for your articles or products.

  • Categorization template refinement:When you want different categories under the same model to have different display styles, Anqicms 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 those under the 'Technical Articles' category.Further, you can also choose to apply the category template settings to all subcategories, thereby simplifying management.

  • Single document template coverage:For certain special content that requires unique display effects, the system also provides ultimate flexibility.When publishing or editing a specific document (whether an article or a product), you can specify a "document template" for it separately.This template takes precedence over model-level and category-level templates, ensuring that the document is presented in the manner you specified.This is very useful when it is necessary to highlight a product or publish a special announcement.

  • Using 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 their content can be used for conditional judgments to achieve 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' and add a strikethrough accordingly.

Accurately call and render content in the template

In the actual template file, you will use various template tags and filters provided by Anqi CMS to retrieve and process content data:

  • Retrieve content details:UsearchiveDetailThe tag can retrieve detailed information about the current page or specified ID content, including the title, text, thumbnail, and most importantly - various custom fields. For example,{% archiveDetail with name="Title" %}It will display the current document title, while{% archiveDetail with name="price" %}it may show the price of the product (if your product model haspricethis custom field).

  • Loop through custom parameters:For complex custom fields in the content model (such as multiple choice, dropdown selections), or when you need to iterate through all custom fields to dynamically generate tables or lists,archiveParamsTags are particularly important. They can retrieve all custom parameters of a specified document and allow you toforloop through them one by one to display their names and values.

  • Display the content list: archiveListTags are a powerful tool for building list pages. They support fetching content lists by model, category, recommended attributes, sorting methods, and more, and can be combined with pagination tags.paginationImplement a comprehensive list display function.

  • Logical control and data processing: ifTags are used for conditional judgments, such as determining whether a custom field has a value before deciding whether to display it;forThe tag is used for looping through lists or arrays. Also, don't forget to use various practical filters, such assafeUsed for safely outputting HTML contentthumbUsed for getting image thumbnailsstampToDateUsed to format timestamps as wellrenderUsed to render Markdown content into HTML, which can help you better format and present data.

Through the above multi-level template configuration and powerful template tag functions, AnQi CMS ensures that you can create a unique and highly customized front-end display effect according to any content model, category, or even the specific needs of a single piece of content.


Frequently Asked Questions (FAQ)

  1. How to set up different list page layouts for the 'Phone' category and the 'Computer' category under the 'Product' model?Answer: You can edit the categories 'Mobile' and 'Computer' separately in the 'Content Management' -> 'Document Category' section of the backend. In the category editing interface, find the 'Category Template' option, and specify different template files for them, for exampleproduct/list-phone.htmlandproduct/list-computer.htmlThis way, when users visit these categories, the system will load the corresponding templates to render the list page.

  2. Ask: My 'article' model has a custom field called 'recommendation index', and only when the recommendation index is greater than 5, will a 'hot recommendation' indicator be displayed below the title on the article detail page. Can this be done?Yes, it is absolutely possible. First, make sure that the 'article' model has set the 'recommendation index' as a numeric custom field. Then in your article detail template (such asarticle/detail.htmlIn it, you can usearchiveDetailLabel gets the value of this field and combines itifLogical judgment controls the display. The code might look something like this:{% archiveDetail recommendIndex with name="推荐指数" %}, then{% if recommendIndex > 5 %}<span>热门推荐</span>{% endif %}.

  3. Ask: I have created a content model named "Service" and also added content, but the front-end page shows a blank or error when accessed. How should I troubleshoot?Answer: This is usually due to the lack of the corresponding model-level template file.After you create a content model, you need to create default detail page and list page template files for it.For example, if your model table name isservicePlease,templateCreate in the directoryservice/detail.htmlandservice/list.htmlFile, and ensure that these files contain the basic calling tags of the model content.If there are still issues, check whether the new model's URL rules are correctly configured in the background "pseudo-static rules".