How to customize the display layout of the article detail page in AnQi CMS?

Calendar 👁️ 59

When building a website with AnQiCMS, we often need to make different types of articles or specific articles have unique appearances and layouts to better display content and enhance user experience.AnQiCMS provides a flexible mechanism that allows users to customize the display layout of article detail pages according to their needs, whether it is for the entire content model, a specific category, or a single independent article.

Understanding and utilizing these customization capabilities is the key to leveraging the advantages of AnQiCMS content management. Below, we will introduce step by step how to implement the personalized layout of the article detail page.

Flexible content model: the foundation of custom data structures

To customize the display layout of the article detail page, you first need to start with the content itself.AnQiCMS's flexible content model is the foundation for achieving this goal.The content model is like a blueprint for website content, defining the fields contained in different types of content (such as "articles" and "products").

By adding a "custom field" in the "content model" management backend, you can add unique data points such as "author bio", "product parameters", and "additional image sets" to your articles.These custom fields not only enrich the content of the article but also provide more elements for subsequent layout design.For example, if you need to display the 'inventory' and 'price' fields on your product detail page, you can define them in the product model and then call them to display in the detail page template.

Choosing and prioritizing template files

AnQiCMS shows article detail pages according to certain priority rules and selects the template file to be used. Understanding these rules can help us accurately control the layout:

  1. Default model detail pageThis is the most basic template, usually named{模型table}/detail.htmlFor example, the default detail page of an article model may bearticle/detail.htmlWhen no more specific template is specified, the system will use this template by default.

  2. Article ID exclusive detail pageIf you need to specify a completely unique layout for a specific article, you can create a naming format of{模型table}/detail-{文档ID}.htmlThe template file. For example, if an article with ID 10 belongs toarticlemodel, it can be createdarticle/detail-10.html. Once it exists, the template will take precedence over the model's default detail page.

  3. Set independent article template:Except for the naming method by ID mentioned above, AnQiCMS also allows you to specify a custom template file directly through the "Document Template" field when editing a single article (for example,download.htmlThis setting has the highest priority and will override all default rules at the model and ID levels. This means that even if you havearticle/detail.htmlorarticle/detail-10.htmlIf an article with ID 10 has set the "document template" tomy-custom-layout.htmlthen the system will usemy-custom-layout.htmlto render.

  4. category template settingsIn editing article categories, there is a "category template" field.You can specify a unified detail page template for a specific category (such as "News Information" or "Product Display").Further, you can also choose whether to apply it to subcategories, so that the template can be automatically inherited to all subcategories below it.When accessing the article detail page through a category link, if the category or its parent category has set a "document template" and the article itself does not specify a more specific template, this category template will be used.

In summary, the priority of template selection is from high to low:Set independent article template>Article ID exclusive detail page>category template settings>Default model detail page. This hierarchical structure allows you to flexibly control the display layout of the article according to your needs.

Deep into template editing: Building a personalized layout

Once you have determined the template file to modify or create (they are usually located in/templatethe current theme directory under the folder, with.htmlwith the suffix), the actual layout construction work follows.AnQiCMS's template engine is similar to Django, using concise syntax to display data and control logic.

  1. Gathering the core information of the articleIn the detail page template, the most critical thing is to obtain the data of the current article. You can usearchiveDetailTag to get the title, content, publication time, and view count of the article. For example, to display the article title:<h1>{% archiveDetail with name="Title" %}</h1>. To display the article content:<div>{% archiveDetail archiveContent with name="Content" %}{{archiveContent|safe}}</div>. Note that for rich text content, in order to correctly parse HTML tags, it is usually necessary to add|safea filter. Dates and times can be formatted usingstampToDatea filter, such as{{stampToDate(archive.CreatedTime, "2006-01-02")}}.

  2. Display custom field: If you define a custom field in the content model, you can flexibly call it on the detail page. If you know the name of the custom field (for exampleauthorIt can be directly passed through{% archiveDetail with name="author" %}It can be displayed.archiveParamsTags:

    {% archiveParams params %}
        {% for item in params %}
            <div><span>{{item.Name}}:</span><span>{{item.Value}}</span></div>
        {% endfor %}
    {% endarchiveParams %}
    

    For custom fields of image type (such asarcimages),You can also iterate through its values to display them:

    {% archiveDetail arcimages with name="arcimages" %}
        {% for img in arcimages %}
            <img src="{{img}}" alt="" />
        {% endfor %}
    
  3. Enrich the page contentA complete article detail page usually does not only contain the article itself. AnQiCMS provides various tags to enrich the page content:

    • Previous/Next article: Use.prevArchiveandnextArchiveTags can conveniently add navigation links.
    • Related articles:archiveListLabel collaborationtype="related"The parameter can automatically retrieve recommendations related to the current article.
    • Article tags: PasstagListTags can list the tags associated with the current article and link to the tag page.
    • Comment ListIf the comment feature is enabled,commentListthe tag can display users' comments on the article.
  4. Modular design and auxiliary tags: In order to maintain the neatness and maintainability of template code, it is recommended to adopt a modular design. Useincludetags to include common template fragments, such as header (partial/header.html) and the footer (partial/footer.html) or sidebar (partial/sidebar.htmlThis avoids repetition of code, making it easier to modify common parts.

By following these steps, combining your understanding of AnQiCMS backend management features and template tags, you can freely design and adjust the layout of the article detail page to meet the display needs of the content while maintaining consistency with the overall style of the website, providing an excellent user experience.

Frequently Asked Questions (FAQ)

  1. How to apply a unique display layout for a single article?You can find the 'Document Template' field when editing specific articles in the background. In this field, enter the name of your custom template file (for examplemy-unique-article-layout.htmlMake sure the file is in your template design package. AnQiCMS will prioritize the template you specify for the article.

  2. How can I display custom fields of an article in a template?If the custom field name ismyCustomField, you can use it in the template.{% archiveDetail with name="myCustomField" %}Directly display its value. If the field stores rich text HTML content, please be sure to add|safea filter such as{{archiveDetailWithCustomField|safe}}

Related articles

How to retrieve and display detailed information about website users or user groups (such as VIP level, balance)?

In Anqi CMS, implementing the acquisition and display of detailed information of website users or user groups is a key link in building personalized member systems and enriching user experience.Whether it is to display the user's VIP level, account balance, or the name of the user group they belong to, AnQiCMS provides intuitive and powerful template tags to help us easily achieve these functions. ### Deep Understanding of AnQiCMS User and User Group System AnQiCMS is built with a complete user management and user group (VIP system) function.

2025-11-08

How to customize and output Json-LD structured data in AnQiCMS template to optimize search engine display?

In today's digital marketing environment, the importance of Search Engine Optimization (SEO) is self-evident, and structured data is one of the key factors for improving a website's performance on Search Engine Results Pages (SERP).AnQiCMS is a system focused on providing efficient content management solutions, which offers powerful SEO optimization tools to website operators with its flexible customization and output of Json-LD structured data in templates.

2025-11-08

How to integrate captcha functionality in comment or message form to prevent spam?

Websites and article comments are an important bridge for interaction between websites and users, and they can effectively improve the activity and user stickiness of the content.However, these open interactive areas are often targeted by spammers, and a large amount of meaningless or malicious information not only damages the image of the website but may also affect search engine rankings.To effectively curb such problems, integrating a captcha function into the message or comment form is an effective method.A safe CMS as an efficient website building tool, fully considering common challenges in content operation and providing convenient solutions

2025-11-08

How to dynamically build and display custom form fields for leaving messages in the template?

In website operation, the message form is an important bridge for users to interact with the website, collect user feedback, or potential customer information.A flexible and customizable feedback form can greatly enhance the practicality and user experience of a website.AnQiCMS (AnQi CMS) provides strong support in this regard, allowing users to customize message form fields in the background and dynamically build and display these fields in the front-end templates, thereby meeting various personalized business needs.### AnQiCMS留言表单的灵活性 AnQiCMS

2025-11-08

How to call the article list under a specific category in Anqi CMS template?

Managing and displaying content in Anqi CMS is one of its core strengths, and flexibly calling the list of articles under specific categories is an indispensable function in website content operation.No matter if you want to display the latest articles of a special topic on the homepage or show popular recommendations under the current category in the sidebar, AnQi CMS template tags can help you easily achieve this.The Anqiz CMS template system uses a syntax similar to the Django template engine, which is intuitive and powerful.

2025-11-08

Does AnQi CMS support lazy loading of images in article content?

In a content management system, the loading efficiency of images is crucial for website performance and user experience, especially for articles with many images.Many users may be concerned, does AnQiCMS (AnQiCMS) support lazy loading of images in article content to optimize page loading speed. The answer is affirmative, Anqi CMS **supports** the lazy loading display of images in article content.This is due to its flexible template engine and fine-grained control over content display.Although Anqi CMS itself as a backend content management system does not execute lazy loading logic directly in the browser

2025-11-08

How to set up multilingual content switching display function for Anqi CMS website?

In today's global internet environment, allowing websites to support multiple language displays has become a key step for many enterprises to expand into international markets and serve diverse user groups.AnQiCMS (AnQiCMS) is a powerful content management system that has built-in flexible multilingual support mechanisms to help users easily switch between multilingual displays of website content.To set up multilingual content switching functionality for your Anqi CMS website, we need to understand two main implementation approaches: one is the template-level translation of website interface text**

2025-11-08

How to optimize the URL structure of Anqi CMS to improve search engine display effect?

In website operation, URL structure is one of the key factors affecting search engine visibility and user experience.A clear, logical, and search engine-friendly URL that allows the crawler to better understand the website content, thereby improving the website's ranking in search results.AnQiCMS (AnQiCMS) took this into consideration from the very beginning, providing multiple features to help optimize the URL structure of websites for better search engine display effects. ### Core Function Analysis: How AnQi CMS Creates Friendly URL Structures **1.

2025-11-08