How to obtain document detail data and display content in AnQiCMS template?

Calendar 👁️ 55

As an experienced CMS website operation person in the safety industry, I know that it is crucial to efficiently and accurately obtain and present document detail data in terms of content display.A well-crafted detail page not only meets users' in-depth information needs, but also effectively enhances the stickiness of the website and search engine performance through optimizing content structure and user experience.

In Anqi CMS, taking advantage of its flexible Django template engine syntax, getting and displaying document detail data is a direct and powerful process.The core lies in using specially designed template tags, which can accurately extract the required information from the database and present it in a structured way on your web page.

Core tag: Get document detail data

The main tag used to obtain detailed document data in the Anqi CMS template isarchiveDetail.This tag is the foundation for building any article, product, or other document detail page based on a content model.Through it, you can access the title, content, images, creation time, category, and even any custom fields of the document.

UsearchiveDetailThe basic syntax of tags is:{% archiveDetail 变量名称 with name="字段名称" %}. Among them,nameThe parameter specifies the specific document field you want to obtain, and变量名称It is an optional parameter, which is used when you need to store the obtained data into a variable for subsequent more complex processing.If the variable name is not specified, the tag will directly output the field content.

In most cases, in the document detail page template ({模型table}/detail.htmlor{模型table}/detail-{文档ID}.html) in, archiveDetailThe tag will default to retrieving the data of the currently visited document, therefore no additional document ID needs to be specified. However, if you need to retrieve the details of a specific document on other pages (such as the homepage or list page), you can do so byidortokenParameters to explicitly specify the target document, such as{% archiveDetail with name="Title" id="1" %}or{% archiveDetail with name="Title" token="your-document-alias" %}. For users with multi-site deployments,siteIdthe parameter allows you to retrieve data across sites.

Display the basic information of the document

The document title is the first element that users pay attention to. You can use{% archiveDetail with name="Title" %}to display the document title. Similarly, the introduction or description of the document can be displayed through{% archiveDetail with name="Description" %}Retrieve.

The main content of the document is the core of the detail page. It uses{% archiveDetail with name="Content" %}This will output the full content of the document. It is worth noting that if your content is written using a Markdown editor, you may need to use an extrarender=trueParameters to ensure Markdown is correctly rendered as HTML, for example{% archiveDetail archiveContent with name="Content" render=true %}{{archiveContent|safe}}. To prevent potential XSS attacks, it is strongly recommended to use for outputting content that includes HTML.|safeFilter. In addition, to optimize page loading speed, you can also combinelazy="data-src"parameters to implement lazy loading of images.

the link of the document (Link) and reading volume (Views), Creation time (CreatedTime), and Update time (UpdatedTime) are also common components of the detail page. For example,{{stampToDate(archive.CreatedTime, "2006-01-02")}}This format timestamp tag can convert timestamps into readable date format. The cover image of the document usually hasLogo(First image) andThumb(Thumbnail), if the document contains multiple images as a carousel or album, you can accessImagesField retrieves an array of image URLs, which you can iterate through to display all images.

In-depth mining of associated data

A document detail page often contains not only the data of the document itself, but also its associated categories, related tags, and various custom parameters defined in the content model.

Category information: PassarchiveDetailTags retrieved from comments.CategoryField, can directly access the ID, title, link, description of the category information. For example,{% archiveDetail archiveCategory with name="Category" %}<a href="{{ archiveCategory.Link }}">{{ archiveCategory.Title }}</a>Easily display the name and link of the document category. You can also use it separately.categoryDetailtags, by passing the document'sCategoryIdto get detailed information about the category.

Document Tag: Document tags are another important way to associate content.archiveDetailTags themselves do not directly output the tag list, but you can combinetagListtags, by passing the current document's ID (itemId=archive.IdTo get and display all related tags. This allows users to discover more relevant content based on their interests.

Custom parameter: The AnQi CMS content model allows you to define unique custom fields for different types of documents.For example, a product model may have fields such as "pricearchiveParamsTo get tags. By iterating through.archiveParamsreturnedparamsArray, you can dynamically display all custom field names and values, or specifyname="自定义字段名"to get the value of a specific custom field. For example,{% archiveDetail with name="author" %}will directly output the name ofauthorCustom field content.

Case study: Build a typical document detail page

To better understand the application of the above tags, let's look at two common application scenarios:

Typical article detail page layout

You may combine tags in this way to display information on an article detail page:

<article>
    <h1>{% archiveDetail with name="Title" %}</h1>
    <div class="meta-info">
        <a href="{% categoryDetail with name='Link' %}">所属分类:{% categoryDetail with name='Title' %}</a>
        <span>发布日期:{% archiveDetail with name="CreatedTime" format="2006年01月02日" %}</span>
        <span class="tags">标签:
            {% tagList tags with itemId=archive.Id limit="5" %}
            {% for item in tags %}
            <a href="{{item.Link}}">{{item.Title}}</a>
            {% endfor %}
            {% endtagList %}
        </span>
        <span>浏览量:{% archiveDetail with name="Views" %}</span>
    </div>
    <div class="document-content">
        {%- archiveDetail articleContent with name="Content" render=true lazy="data-src" %}
        {{articleContent|safe}}
    </div>
</article>

Typical product detail page layout

For the product detail page, in addition to basic information, it will also highlight product images, parameters, and contact information:

<section class="product-detail">
    <div class="product-gallery">
        {% archiveDetail productImages with name="Images" %}
        {% if productImages %}
            {% for img in productImages %}
                <img src="{{img}}" alt="{% archiveDetail with name='Title' %}" />
            {% endfor %}
        {% else %}
            <img src="{% archiveDetail with name='Logo' %}" alt="{% archiveDetail with name='Title' %}" />
        {% endif %}
    </div>
    <div class="product-info">
        <h1>{% archiveDetail with name="Title" %}</h1>
        <div class="product-params">
            {% archiveParams params %}
            {% for item in params %}
            <p><span>{{item.Name}}:</span><span>{{item.Value}}</span></p>
            {% endfor %}
            {% endarchiveParams %}
        </div>
        <p class="description">{% archiveDetail with name="Description" %}</p>
        <div class="contact-info">
            联系我们:<a href="tel:{% contact with name='Cellphone' %}" rel="nofollow">{% contact with name="Cellphone" %}</a>
        </div>
    </div>
    <div class="product-content">
        <h2>产品详情</h2>
        {%- archiveDetail productFullContent with name="Content" render=true %}{{productFullContent|safe}}
    </div>
</section>

In the above examples, we combinedarchiveDetail/categoryDetail/tagList/archiveParamsandcontactCreated a document detail display page with multiple tags and complete functions.By this modular approach, you can flexibly combine these tags according to specific business needs to create unique content detail pages.

Frequently Asked Questions

How can you ensure that HTML tags or Markdown syntax in the document content are displayed correctly, rather than as plain text output?

When you enter document content with HTML tags or Markdown syntax in the content editor, by default, for security considerations, AnQi CMS may escape the HTML content, causing the tags to not render. To ensure that the content is displayed correctly as rich text, you need to outputContentUse field when|safeFilter. For example,{{ archiveContent|safe }}. If the content is entered through a Markdown editor, you also need to specify thearchiveDetailthe tag withrender=trueparameter to indicate that the system should convert Markdown to HTML, for example{% archiveDetail archiveContent with name="Content" render=true %}{{archiveContent|safe}}.

Question two: How can I display more information about the document category on the document detail page, such as the category logo or description?

The document detail page defaults to loading the current document'sCategoryAn object, you can access it byarchiveDetaillabel'sname="Category"obtaining this object with parameters, then accessing its sub-properties, such as{% archiveDetail docCategory with name="Category" %}{{ docCategory.Logo }}. In addition, you can also usecategoryDetailtags, by passing the current document'sCategoryIdTo independently obtain detailed classification information, for example, first obtain the document classification ID{% archiveDetail docCatId with name="CategoryId" %}Then use{% categoryDetail with name="Logo" id=docCatId %}To obtain the classification logo.

Question 3: I have added custom fields to my document content model, how can I display these fields on the document detail page?

The Anqi CMS provides two main ways to display custom document fields. First, if your custom field name isauthor, you can use it directly in the template.{% archiveDetail with name="author" %}Output its value. Secondly, for scenarios that require displaying all custom fields in a loop or performing more complex logic processing, you can usearchiveParamsLabel. This label will return an array or map containing all custom field names and values, you can iterate over it or access it as needed, for example:

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

Related articles

How to call the article or product category list in AnQiCMS template and implement multi-level nesting?

As a senior website operator at AnQiCMS, I fully understand that efficient content organization and presentation are crucial for user experience and SEO.Categorization list, especially multi-level nested categorization lists, can clearly present the hierarchical structure of the website's content, guide users to discover more interesting content, and also provide clear site structure information for search engines.This article will detail how to call the article or product category list in the AnQiCMS template and implement a multi-level nested display effect.

2025-11-06

How to get and display the navigation list and its sub-menu in AnQiCMS template?

## AnQiCMS Navigation List and Submenu Display in Templates As an experienced AnQiCMS website operations personnel, I am well aware of the importance of a clear and efficient website navigation for user experience and content access.AnQi CMS provides a powerful and flexible navigation list tag `navList` for template developers, making it easy to obtain and display the main navigation, footer navigation, and even more complex multi-level navigation structures with submenus on the website front-end.

2025-11-06

How to call the TDK (Title, Keywords, Description) information of the page in AnQiCMS template?

As a website operator who is well-versed in the operation of AnQiCMS, I deeply understand the importance of TDK (Title, Keywords, Description) information for the performance of the website in search engines and the willingness of users to click.AnQiCMS was designed with SEO-friendliness in mind from the beginning, providing us with flexible and powerful mechanisms to manage these key metadata.Properly calling TDK in the template is the basis for ensuring that website content is efficiently indexed, improves click-through rates, and enhances user experience.

2025-11-06

How to get contact information in AnQiCMS template (such as phone, email)?

As a website operator who has been deeply involved in AnQiCMS for many years, I know the importance of clearly and effectively displaying key information, especially contact information, on the website front-end template.This is not only about user experience, but also the key to building trust and promoting communication.AnQiCMS was designed with this in mind from the beginning, providing intuitive and flexible template tags that allow developers to easily access and display this information.Next, I will elaborate on how to obtain and display contact information in the AnQiCMS template, such as phone and email.

2025-11-06

How to call the previous and next document links in AnQiCMS template?

As a senior CMS website operation personnel in an enterprise, I am well aware of the importance of content navigation for user experience and SEO.On a day when the content of the website is becoming richer and richer, how to guide users to smoothly browse related content is a key factor in enhancing user stickiness and reducing the bounce rate.Today, we will delve into how to cleverly call the links of the previous and next documents in the AnQiCMS template to optimize your website's content structure and user path.### Enhancing User Experience and SEO: Navigation of Previous and Next Documents in AnQiCMS Templates In the Content Management System

2025-11-06

How to display the list of related documents in AnQiCMS template?

As a website operator who has been deeply involved in the CMS of security enterprises for many years, I know that effectively guiding users to discover more interesting content is crucial for enhancing user stickiness and the depth of website visits.Among them, the 'related document list' is undoubtedly one of the core functions to achieve this goal.It not only helps users conveniently explore more related topics, but also has a positive impact on the internal link structure of the website and SEO optimization.

2025-11-06

How to use the for loop in AnQiCMS template to traverse data and handle empty results with the empty tag?

## Master the data traversal and empty result handling in AnQiCMS templates: in-depth analysis of for loops and empty tags AnQiCMS, with its efficient and customizable features, has become the preferred content management system for many content operation teams and small and medium-sized enterprises.It is crucial for the flexibility of template language when building dynamic web pages.

2025-11-06

How to perform conditional judgments (if/elif/else) in Anqi CMS template?

As an experienced CMS website operation personnel, I am well aware that the flexibility of templates is crucial for efficient operation in daily content management.Especially conditional judgment allows us to intelligently control the display and hiding of content based on different data states and business logic, thereby providing users with a more accurate and personalized browsing experience.The Anqi CMS template engine has adopted the syntax style of Django, making the implementation of conditional judgments both powerful and easy to understand.### The basic structure of conditional judgment in AnQi CMS template Conditional judgment in the AnQi CMS template is mainly achieved through

2025-11-06