How to retrieve and display the detailed content of the current article in AnQiCMS

Calendar 👁️ 65

In Anqi CMS, you need to retrieve and display the detailed content of the current article, mainly focusing on the organization of template files and built-in template tags.Understanding these core mechanisms allows you to flexibly control the presentation of articles on the front page.

Core Concept: The composition of the article detail page

In Anqi CMS, the detailed content of each article is usually displayed through a specific template file.This template file will be automatically or manually called by the system according to the content model (such as "article model" or "product model") it belongs to and the settings in the background.By default, AnQi CMS will search fortemplate/{你的模板目录}/{模型table}/detail.htmlThis path is used to render the article detail page. For example, if your article belongs to the "Article Model" (the defaulttableThe name might bearchive), then the system will try to loadtemplate/{你的模板目录}/archive/detail.htmlfile.

In this detail page template, we need to use the powerful template tags provided by Anqicms to "grab" the various data items of the article and display them according to the design.archiveDetailTags are the core to obtain detailed information of articles.

Deep understandingarchiveDetailTag

archiveDetailTags are specifically used to extract detailed data of a single article from the database. Its basic usage is{% archiveDetail 变量名称 with name="字段名称" %}.

  1. To obtain the current article dataWhen you are on the article detail page (such asarchive/detail.htmlUsed inarchiveDetailWhen tagging, it is usually not necessary to specify the article's ID. The system will intelligently identify the article being accessed and automatically retrieve its data.For example, to get the title of the current article, you just need to do this:{% archiveDetail with name="Title" %}

  2. BynameThe parameter specifies the field to be retrieved archiveDetailTag throughnameSpecify the specific field of the article you want to retrieve. These fields include the basic information of the article, SEO information, the content itself, and fields customized through the content model.

    Here are some commonly used fields and their applications:

    • Article title (Title):{% archiveDetail with name="Title" %}This will directly output the title of the article.

    • Article content (Content):{% archiveDetail with name="Content" %}This is the main part of the article page. It is important to note that if the article content contains HTML tags (such as images, links, formatted text, etc.), in order to ensure that these HTML codes can be parsed correctly by the browser rather than displayed as plain text, it is usually necessary to cooperate with|safeThe filter is used. If the article is written in Markdown and you have enabled the Markdown editor in the background, Anqi CMS will automatically convert it to HTML; if you need to manually control it, you can add it in the tag.render=trueorrender=falseParameters. Example:{% archiveDetail articleContent with name="Content" %}{{articleContent|safe}}{% endarchiveDetail %}

    • Publish time (CreatedTime), and Update time (UpdatedTime): These fields return timestamps, and in order to display them in a readable date format on the page, you need to usestampToDateTimestamp formatting tags. Example:{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04") }}(wherearchiveIt is througharchiveDetailTag-defined variable name,2006-01-02 15:04Is the Go language time formatting standard.

    • Article link (Link) Keywords (Keywords), Description (Description), Page views (Views): These fields are similar in terms of access methodTitle.{% archiveDetail with name="Link" %} {% archiveDetail with name="Keywords" %} {% archiveDetail with name="Description" %} {% archiveDetail with name="Views" %}

    • Cover image (Logo/Thumb/Images):LogoGenerally refers to the single main image or large image of an article,Thumbwhich is its thumbnail.ImagesIt may also be a group of images (multiple images). Example:<img src="{% archiveDetail with name="Logo" %}" alt="{% archiveDetail with name="Title" %}" />If there are multiple images, they need to be defined as variables and cycled:{% archiveDetail archiveImages with name="Images" %} {% for img in archiveImages %} <img src="{{img}}" alt="文章图片" /> {% endfor %} {% endarchiveDetail %}

    • Category (Category)This field can retrieve the detailed information of the article category it belongs to. If you need to display the category name or link, you can define it as a variable and then access its properties, or use it directly.categoryDetailTag acquisition. Example:{% archiveDetail currentCategory with name="Category" %} <a href="{{ currentCategory.Link }}">{{ currentCategory.Title }}</a> {% endarchiveDetail %}

    • Tag tag (tagList): The Tag tag of the article is usually notarchiveDetaila direct attribute, but throughtagListtags to obtain. You can inarchiveDetailCall in the contexttagListAnd specifyitemIdFor the current article ID. Example:{% tagList tags with itemId=archive.Id %} {% for tag in tags %} <a href="{{ tag.Link }}">{{ tag.Title }}</a> {% endfor %} {% endtagList %}

    • Custom field (archiveParamsOr retrieve by name)These fields can be obtained in the template in two ways: by content model definition. It supports additional custom fields.

      • Directly by field name.If the name of the field to be called of the custom field isauthorthen it can be{% archiveDetail with name="author" %}.
      • loop through all custom fields: Use.archiveParamsLabel to iterate over all custom fields, which is very useful when the field names are uncertain or when a unified display is needed.{% archiveParams params %} {% for item in params %} <span>{{ item.Name }}:{{ item.Value }}</span> {% endfor %} {% endarchiveParams %}

Step by step to build the article detail page.

After understanding the core tags, we can follow the following steps to build a feature-complete article detail page:

  1. Confirm the location of the template fileFirst, you need to find or create your article detail page template file. For example, if it is an article model, it is usually intemplate/你的模板名称/archive/detail.html.

  2. Get and display basic article informationIndetail.htmlIn the file, you can first place the article title and main content.

    <h1>{% archiveDetail with name="Title" %}</h1>
    <div class="article-content">
        {% archiveDetail articleContent with name="Content" %}{{ articleContent|safe }}{% endarchiveDetail %}
    </div>
    
  3. Display auxiliary informationNext, add the publication date, views, category, and Tag tags, etc., as auxiliary information.

    <div class="article-meta">
        <span>发布日期:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}</span>
        <span>浏览量:{% archiveDetail with name="Views" %}</span>
        <span>所属分类:
            {% archiveDetail currentCategory with name="Category" %}<a href="{{ currentCategory.Link }}">{{ currentCategory.Title }}</a>{% endarchiveDetail %}
        </span>
        <span>标签:
            {% tagList tags with itemId=archive.Id %}{% for tag in tags %}<a href="{{ tag.Link }}">{{ tag.Title }}</a>{% endfor %}{% endtagList %}
        </span>
    </div>
    

    (Note:archive.CreatedTimeHerearchiveIs a hypothetical variable name, if you have not passedwithThe parameter willarchiveDetailThe result is assigned toarchive

Related articles

How to use AnQiCMS template tags to display article lists on the page?

In AnQiCMS, flexibly displaying article lists on website pages is one of the core needs of website content management.Whether it is to build news dynamics, product display, blog articles, or any other content that needs to be presented in a list, the powerful template tag system of AnQiCMS can help you easily achieve it.This article will provide a detailed introduction on how to use the `archiveList` template tag, combining the various functions of AnQiCMS, to efficiently and beautifully present article lists on your website page.### Understand `archiveList`

2025-11-08

How to obtain the Logo image and Banner group image of a specified article or category in Anqi CMS, and apply them flexibly in templates?

## Play with Visual Content: Flexible Calling and Display of Article and Category Logo Images, as well as Banner Group Images in AnQi CMS When building and operating a website, eye-catching visual content is the key to attracting users and conveying the brand image. AnQi CMS understands this and therefore provides a powerful and flexible image management and calling function in the system design, whether it is the cover Logo of the article, the representative thumbnail of the category, or the Banner group images used to create an atmosphere, they can all be easily realized and applied to the website template

2025-11-08

How to ensure that the old link traffic is not lost and the new content is displayed correctly after adjusting the page content structure, by using 301 redirect?

During the operation of a website, content updates, adjustments of the classification structure, or optimization of URL addresses are common operations.However, if not handled properly, these changes are likely to lead to a loss of website traffic and a drop in search engine rankings.幸运的是,AnQiCMS(AnQiCMS)内置了强大的301重定向功能,能够帮助我们平稳地度过这些调整期,确保旧链接的流量能够无缝过渡到新内容。Why 301 Redirects Are Indispensable?301 redirect, i.e., permanent transfer

2025-11-08

How to display different language versions and content on the front-end of a website through a language switcher based on user selection?

AnQi CMS is an efficient and customizable content management system that excels in multilingual support, allowing operators to easily build multilingual websites for global users.By cleverly utilizing its built-in features, we can build a flexible language switcher on the website front-end, accurately presenting different language versions of content based on user preferences, thereby effectively enhancing user experience and expanding market coverage.### Understanding the Core of Multilingual Support Implementing multilingual support in Anqi CMS is not just a simple text replacement, but a systematic workflow.

2025-11-08

How to set and display the TDK information (title, keywords, description) on the home page of AnQiCMS?

In website operation, TDK (Title, Description, Keywords) information is the foundation of Search Engine Optimization (SEO), especially for the homepage, its importance is self-evident.A clear and accurate homepage TDK can effectively help search engines understand the core content of the website, thereby improving the visibility and attractiveness of the website in search results.How can we conveniently and quickly set up and manage these key information in AnQiCMS and ensure that they are presented correctly to users?### One

2025-11-08

How does AnQiCMS achieve independent display of multi-site content under different domain names?

When using AnQiCMS to build and manage websites, users often face the need to create independent sites for different brands, businesses, or regions, and they also hope that these sites can be displayed independently under their respective domain names.AnQiCMS powerful multi-site management function, which is designed to solve this pain point.It allows users to easily create and operate multiple websites with independent content and domain names on the basis of a set of AnQiCMS core programs.### AnQiCMS The Core Concept of Multi-Site Management AnQiCMS

2025-11-08

How to customize AnQiCMS URL static rules to optimize search engine link display?

In today's digital world, a clear, friendly, and easily searchable URL structure is crucial for the visibility of a website.As one of the core functions of a content management system, the custom ability of URL static rules can make your website perform better in search engines.AnQiCMS is a content management system that focuses on SEO optimization and provides very flexible static configuration options, allowing you to easily achieve this goal.### Understanding the Importance of URL Rewrite Static Firstly, let's briefly understand what a pseudo-static URL is

2025-11-08

How to ensure that custom fields of the content model are correctly displayed on the front page in AnQiCMS?

In AnQiCMS, we often encounter situations where we need to display various personalized content.The built-in articles and product models are powerful, but sometimes they still cannot meet specific business needs.At this time, the custom fields in the content model become our helpful assistants, making website content management more flexible.But the custom field is set up, how can we ensure that they are displayed correctly on the website front-end for visitors to see?Today, let's delve deep into this issue. ### Custom Field Creation and Management of Content Model Firstly

2025-11-08