How to get and display the detailed content of the current article in AnQiCMS template?

Calendar 👁️ 68

Build a rich content website, the article detail page is undoubtedly the core.It carries the most specific and valuable information on the website, and it is also one of the pages where users stay the longest and interact the most.In AnQiCMS (AnQi CMS), with its flexible template engine and rich tag system, we can easily obtain and elegantly display the detailed content of the current article.

The AnQiCMS template system is designed simply and efficiently, similar to Django template syntax, using double curly braces{{变量}}Get variable value, single curly braces with a percentage sign{% 标签 %}Invoke feature tag. This allows even developers unfamiliar with the Go language to quickly get started with template customization.

Core tags:archiveDetailDetailed explanation

To get the detailed content of the current article on the article detail page, the most core tag isarchiveDetail. As the name implies, it is specifically used to retrieve the details of a single "archive" (i.e., an article or product, etc.).

When we visit an article detail page, AnQiCMS will automatically identify the article ID of the current page and provide all the data of the article. Usually, you do not need to make any additional configuration and use it directlyarchiveDetailTags can be used to retrieve the article data on the current page.

archiveDetailthe basic usage of tags is{% archiveDetail with name="字段名称" %}.nameThe parameter specifies a specific field of the article you want to retrieve.

The following are some commonly used article fields and their retrieval methods.

  • Article title (Title)To display the article title, you can use{% archiveDetail with name="Title" %}. This will directly output the current article title.
  • Article summary (Description): The article summary is usually used for abstracts or SEO descriptions, the method of obtaining it is{% archiveDetail with name="Description" %}.
  • The article body (Content)This is the core content of the article. Due to the possibility of HTML tags or Markdown syntax in the main text, special attention needs to be paid when displaying in the template.First, the main content needs to be used|safeA filter to ensure that HTML tags are parsed correctly and not displayed as plain text. For example:{{ archiveDetail with name="Content" | safe }}. If your article content is written using a Markdown editor, AnQiCMS providesrender=trueparameters to automatically render Markdown as HTML:{% archiveDetail with name="Content" render=true | safe %}. Moreover, if images in the text need to be implemented lazy loading, you can also specify parameters such aslazy="data-src"to specify the imagesrcas an alias for the property, to coordinate with the front-end lazy loading script.
  • Publish time (CreatedTime) With update time (UpdatedTime): These time fields are usually stored in timestamp format. AnQiCMS providesstampToDateA helper function to format timestamps into readable date strings. For example, displaying the publication date in the format: 2006-01-02{{ stampToDate(archiveDetail with name="CreatedTime"), "2006-01-02") }}.
  • Cover image (Logo,Thumb,Images):LogoGenerally refers to the main image or large image of an article,ThumbAre thumbnails. They can be accessed directly<img>Tag reference:<img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}" />. If the article contains multiple cover images (such as product albums),ImagesThe field will return an array of image URLs. At this point, you need to usefora loop to iterate and display these images:
    
    {% archiveDetail articleImages with name="Images" %}
    <div class="image-gallery">
        {% for imgUrl in articleImages %}
        <img src="{{ imgUrl }}" alt="图片描述" />
        {% endfor %}
    </div>
    {% endarchiveDetail %}
    
  • Category (Category): The classification information of the article can be obtained througharchiveDetailby directly obtaining its classification ID and then combiningcategoryDetailTag to get category name and link:
    
    {% set categoryId = archiveDetail with name="CategoryId" %}
    <a href="{% categoryDetail with name='Link' id=categoryId %}">
        {% categoryDetail with name='Title' id=categoryId %}
    </a>
    
    Or use it directly.{{archive.Category.Title}}Access in this way.
  • Views (Views): Display the number of times the article has been viewed simply:{% archiveDetail with name="Views" %}.
  • Custom field: AnQiCMS supports adding custom fields for different content models (such as articles, products). If you add custom fields like "author", "source", and so on for the article model in the background, you can obtain them in two ways:
    1. Directly access a single field:{% archiveDetail with name="author" %}.
    2. Loop through all custom fields: Use.archiveParamsLabel. This is very useful when you need to dynamically display all additional properties:
      
      {% archiveParams params %}
      <ul class="article-meta">
          {% for item in params %}
          <li><span>{{ item.Name }}:</span>{{ item.Value }}</li>
          {% endfor %}
      </ul>
      {% endarchiveParams %}
      

Actual application example: Build an article detail page

Summing up the tags, a typical article detail page template may look like this, it shows the article title, category, publish time, tags, views, and content:

<article class="article-detail">
    <h1 class="article-title">{% archiveDetail with name="Title" %}</h1>
    <div class="article-meta-info">
        {# 获取文章分类信息 #}
        {% set categoryId = archiveDetail with name="CategoryId" %}
        <span class="category-link">
            分类:<a href="{% categoryDetail with name='Link' id=categoryId %}">{% categoryDetail with name='Title' id=categoryId %}</a>
        </span>
        {# 格式化显示发布时间 #}
        <span class="publish-date">发布于:{{ stampToDate(archiveDetail with name="CreatedTime"), "2006-01-02") }}</span>
        {# 显示文章浏览量 #}
        <span class="views-count">阅读:{% archiveDetail with name="Views" %}次</span>
        {# 获取并显示文章标签 #}
        <div class="article-tags">
            标签:
            {% tagList tags with itemId=archive.Id limit="5" %}
            {% for tag in tags %}
            <a href="{{ tag.Link }}">{{ tag.Title }}</a>
            {% endfor %}
            {% endtagList %}
        </div>
    </div>

    {# 显示文章主图,如果存在的话 #}
    {% set articleLogo = archiveDetail with name="Logo" %}
    {% if articleLogo %}
    <div class="article-thumbnail">
        <img src="{{ articleLogo }}" alt="{% archiveDetail with name='Title' %}" />
    </div>
    {% endif %}

    <div class="article-content">
        {# 显示文章正文,如果为Markdown则渲染,并确保HTML安全解析 #}
        {% archiveDetail articleContent with name="Content" render=true %}
        {{ articleContent | safe }}
        {% endarchiveDetail %}
    </div>

    {# 显示上一篇和下一篇文章链接 #}
    <div class="article-navigation">
        <div class="prev-article">
            {% prevArchive prev %}
            上一篇:{% if prev %}<a href="{{ prev.Link }}">{{ prev.Title }}</a>{% else %}没有了{% endif %}
            {% endprevArchive %}
        </div>
        <div class="next-article">
            {% nextArchive next %}
            下一篇:{% if next %}<a href="{{ next.Link }}">{{ next.Title }}</a>{% else %}没有了{% endif %}
            {% endnextArchive %}
        </div>
    </div>
</article>

This code demonstrates how to combine multiple tags to build a relatively complete article detail page.

Advanced tips and注意事项

  • Get specific article details: AlthougharchiveDetailDefault to fetching the article on the current page, but you can also specifyidortokenparameters to fetch details of other articles. For example:{% archiveDetail with name="Title" id="123" %}to get the title of the article with ID 123.
  • Debug variableIn the process of template development, if the structure of a variable is uncertain, you can use|dumpthe filter to print out its detailed structure, which is very helpful for debugging:{{ archive|dump }}.
  • SEO optimizationThe TDK (Title, Description, Keywords) of the article detail page can be obtained throughtdktags, whereasarchiveDetaillabel'sSeoTitle/Keywords/DescriptionThe field directly corresponds to the SEO settings of the article. In addition, the standardized link (CanonicalUrl) is also an important part of SEO, which can be{% tdk with name="CanonicalUrl" %}obtained and applied.

By using these tags and techniques, AnQiCMS users can be very flexible and efficient in obtaining and displaying detailed article content in templates, meeting the diverse needs of website content display.


Frequently Asked Questions (FAQ)

  1. How to display articles

Related articles

What ways does AnQiCMS support for sorting the article list display, such as by views or publication time?

The display order of the website content list is one of the key factors affecting user experience and content operation effects.An excellent CMS system should provide a flexible sorting mechanism, allowing operators to freely adjust the display of articles according to content characteristics and promotion strategies.AnQi CMS deeply understands this, providing users with various ways to sort article lists, helping you accurately control content exposure and traffic guidance.### Core Sorting Feature: The Powerful Application of `archiveList` Tag In AnQi CMS

2025-11-07

How to display a document list on the AnQiCMS website based on a specific category ID?

In AnQiCMS, displaying a document list based on a specific category ID is a very basic and commonly used feature, which allows us to flexibly organize and present website content.AnQiCMS's powerful template tag system makes this operation intuitive and efficient.No matter where you want to manually insert a category of documents on a page, or want the entire category page to automatically display the documents under it, the system provides the corresponding solutions.

2025-11-07

How does AnQiCMS display the latest article list on the homepage?

The homepage is the first impression of visitors arriving at the website, and the timely update of the latest article list can effectively enhance the activity and user stickiness of the website.For users using AnQiCMS, displaying the latest list of published articles on the homepage is a basic and important feature, which can be easily achieved through the flexible template tags provided by the system.AnQiCMS with its efficient and customizable features provides users with an intuitive template system.You do not need to delve deeply into the complex backend code, just master its powerful template tag usage

2025-11-07

How to display the previous article and

In website content operation, the user experience of the document detail page is crucial.A well-designed page not only effectively displays content but also guides visitors to delve deeper into more related information.Among them, providing the "Previous" and "Next" navigation functions for users is a commonly used and efficient strategy to improve the internal link structure of the website, reduce the bounce rate, and optimize the user's browsing path.This not only helps users conveniently explore more content, but also conveys the relevance and depth of the website's content to search engines, which has a positive impact on SEO.

2025-11-07

How to implement the display of multi-level navigation menus in AnQiCMS and support secondary dropdown menus?

A clear and intuitive navigation system is the key to the success of any website, it can guide visitors to quickly find the information they need and greatly enhance the user experience.AnQiCMS as an efficient content management system, provides flexible and powerful functions to build and manage the navigation menu of the website, including perfect support for multi-level structures and secondary dropdown menus. ### Define your navigation structure in AnQiCMS backend The first step in building a multi-level navigation menu in AnQiCMS is to configure it in the backend management interface.You can go to the **"Back-end Settings"** area

2025-11-07

How to customize the footer information of the AnQiCMS website, such as copyright statement and filing number?

## Custom AnQiCMS website footer information: Copyright statement and record number setting guide The website footer, although at the bottom of the page, is an indispensable area for conveying important information, establishing brand trust, and meeting legal requirements.A clear and complete footer can enhance the professionalism of the website and provide visitors with convenient legal information and contact details.This article will introduce in detail how to customize the copyright statement, filing number, and other information you want to display in the footer of the website in AnQiCMS.

2025-11-07

How to call and display the website logo image in AnQiCMS template?

In website operation, the Logo is not only a visual symbol of the brand, but also an important part of the website's professionalism and user experience.AnQiCMS (AnQiCMS) provides an intuitive and simple way to manage and call the website logo, allowing you to easily display your brand image in all corners of the website.This article will introduce how to set your website logo in the Anqi CMS backend and guide you to accurately and flexibly call and display it in the front-end template, ensuring that your brand image is perfectly presented.### In Anqi CMS backend to set the website logo First

2025-11-07

How to display the links and titles of the previous and next articles on the article detail page?

In AnQi CMS, adding navigation links for the previous and next articles on the article detail page is a key step to enhance the user reading experience and optimize the internal link structure of the website.This not only encourages visitors to browse more content, but also helps search engines better understand the structure of the website.AnQi CMS provides a very intuitive and easy-to-use template tag, allowing us to easily implement this feature.Understanding the "Previous" and "Next" navigation mechanism The template system of Anqi CMS is designed to be very flexible.

2025-11-07