How to use AnQiCMS template tags to accurately control the display content of article detail pages?

Calendar 👁️ 73

The website is operational, and the article detail page is a key link for users to deeply interact with content and understand products or services.A well-designed, accurate information presentation detail page, which can not only significantly improve user experience, but also effectively assist in SEO optimization.In AnQiCMS such a flexible and efficient content management system, we can finely control the content of the article detail page by cleverly using its template tags.

AnQiCMS is developed in Go language, with its concise and efficient architecture, providing powerful functions similar to the Django template engine.This means that even if you do not have a deep development background, you can still accurately control the display of each element on the page by using an intuitive tag syntax, just like building with blocks.

Core tags:archiveDetailControl everything

In the article detail page, all content revolves around the currently displayed article. Anqi CMS provides the core ofarchiveDetailtags, which are the entry points to obtain all detailed information about the article.

Generally, in the template file of the article detail page (such asarchive/detail.htmlIn it, you do not need to specify the article ID, archiveDetailThe tag automatically identifies the article on the current page and provides all its data. The most direct way to call it is like this:

<h1>{{archive.Title}}</h1>
<div class="article-content">
    {{archive.Content|safe}}
</div>

HerearchiveIs the current article object provided by the system by default, througharchive.TitleCan retrieve the article title,archive.ContentThen retrieve the article content. It is particularly important to note that the article content usually contains HTML code, and in order for the browser to parse it correctly rather than display it as plain text, we need to cooperate with|safefilter usage.

Of course, if you want to getnot the current pagethe specific article details,archiveDetailit also supports getting throughidortokento specify the parameters:

{% archiveDetail otherArticle with name="Title" id="100" %}
<div>这篇是ID为100的文章标题:{{ otherArticle }}</div>

here we define a variable namedotherArticleto receive the title of the specified article.

Basic information display: the construction of the article framework

A complete article detail page, in addition to the title and content, it also needs to display many auxiliary information. AnQiCMS tags can help you easily achieve these.

  1. Publishing and Update TimeThe time of article publication and update is very important to users and search engines.CreatedTimeandUpdatedTimeThe field returns a timestamp, which we can use.stampToDateThe tag can be used to format it into a readable date and time:

    <span>发布日期:{{stampToDate(archive.CreatedTime, "2006年01月02日 15:04")}}</span>
    <span>最后更新:{{stampToDate(archive.UpdatedTime, "2006-01-02")}}</span>
    

    Among them"2006-01-02 15:04"Is a time formatting template unique to the Go language, very flexible.

  2. Article viewsDisplaying the number of times an article has been read usually attracts more users to click.

    <span>阅读量:{% archiveDetail with name="Views" %} 次</span>
    
  3. Thumbnail and imageThe cover image or group image of the article can make the page more attractive.

    <img src="{% archiveDetail with name="Logo" %}" alt="{{archive.Title}}" class="article-cover">
    

    LogoThe field usually returns the first image or thumbnail of the article. If the article contains multiple images as a gallery (for example, on a product detail page),ImagesThe field will return an array of image URLs, you can useforLoop through and display:

    <div class="image-gallery">
        {% archiveDetail articleImages with name="Images" %}
        {% for imgUrl in articleImages %}
            <img src="{{imgUrl}}" alt="{{archive.Title}}的图片" loading="lazy">
        {% endfor %}
        {% endarchiveDetail %}
    </div>
    

    Hereloading="lazy"It is an HTML attribute used to implement lazy loading of images, improve page performance, and when used with AnQiCMS tags, it can achieve very good effects. In addition,archiveDetaillabel'sContentThe field supports passing throughlazy="data-src"Parameters to implement lazy loading of images, or throughrender=trueParameters to render Markdown content on the front end.

Link content with navigation: enrich the page ecosystem

The detail page is often not isolated, it needs to be associated with other content to provide convenient navigation.

  1. CategoryDisplay the category of the article, and provide a category link for easy browsing of similar articles. It can be accessed directly througharchiveObject to get category information:

    <span>所属分类:<a href="{{archive.Category.Link}}">{{archive.Category.Title}}</a></span>
    

    If you need more detailed classification information, you can also usecategoryDetailTags:

    {% categoryDetail currentCategory with id=archive.CategoryId %}
    <span>分类描述:{{currentCategory.Description}}</span>
    
  2. Tag tagTags are another way to categorize articles, helping users discover related topics. UsetagListTags, and pass in the current article ID, you can retrieve and display all related tags:

    <div class="article-tags">
        {% tagList tags with itemId=archive.Id limit="10" %}
        {% for tag in tags %}
            <a href="{{tag.Link}}" class="tag-item">{{tag.Title}}</a>
        {% endfor %}
        {% endtagList %}
    </div>
    
  3. Previous/Next articleProvide navigation at the bottom of the article,

Related articles

How does AnQiCMS handle image resource management and optimization?

In the daily operation of websites, images are not only an important part of the content, but also a key factor affecting website performance and user experience.Efficient image resource management and optimization, can significantly improve website loading speed, improve search engine rankings, and effectively protect the copyright of original content.AnQiCMS is a system born for content operation, which provides comprehensive and practical functions in image processing to help us easily meet these challenges.### A comprehensive centralized management of image resources AnQiCMS provides a centralized management platform for image resources

2025-11-08

How does AnQiCMS determine if a string or array contains a specific keyword and display content accordingly?

In website operation, we often need to dynamically adjust the display of the page based on the specific attributes or keywords of the content.For example, when the article title includes the words 'latest', we may want to add a prominent 'NEW' label; or when a product description mentions 'Free Shipping', an icon showing free shipping should be automatically displayed.AnQiCMS (AnQiCMS) provides powerful template functions and rich filters, making it easy to meet these needs.

2025-11-08

How to remove specific characters or spaces from a string in AnQiCMS template?

In website content management, string processing is inevitable and crucial.In order to maintain the beauty of the page, keep the standardization of data output, or for SEO optimization, we often need to make fine adjustments to text content, such as removing extra spaces, punctuation marks, or other specific characters.AnQiCMS provides a flexible and powerful template engine, allowing us to easily implement these string operations in front-end templates.

2025-11-08

How to split a string into an array by a specified separator and iterate and display it in the template in AnQiCMS?

In website operations and content management, we often encounter such scenarios: a certain field in the background stores multiple related information, such as multiple keywords of an article, various functional tags of a product, or multiple aliases of an author.This information is usually connected into a string with commas, semicolons, or other specific symbols.When it is necessary to display this information one by one or perform style processing in the website front-end template, it is necessary to split this string into independent items and then traverse and display them one by one.AnQiCMS provides a powerful and flexible template engine, its syntax style is similar to

2025-11-08

In AnQiCMS, how to implement dynamic pagination on the article list page and control the number of items displayed per page?

Manage website content in Anqi CMS, the article list page is usually one of the main entry points for users to browse information.To provide a smoother user experience and optimize page loading performance, it is particularly important to implement dynamic pagination and flexible control over the number of items displayed per page.AnQi CMS provides powerful and easy-to-use template tags that allow us to easily implement these features.### Core Concept: The Foundation of Dynamic Pagination and Page Size Control In Anqi CMS, the implementation of dynamic pagination for article lists mainly relies on two core template tags: 1. **`archiveList`

2025-11-08

How to customize the URL rewrite rules of AnQiCMS website to optimize search engine display effect?

In website operation, the structure of the URL (Uniform Resource Locator) plays a crucial role in search engine optimization (SEO) and user experience.A clear and meaningful URL can not only help search engines better understand the content of the page, but also enable users to have expectations of the page content before clicking, enhancing trust.AnQiCMS as a system focusing on enterprise content management, fully understands this point, and therefore provides a flexible feature for customizing pseudostatic rules.

2025-11-08

What content models does AnQiCMS support and how do they affect the front-end content display?

AnQiCMS is a major highlight in content management with its flexible content model support, which allows the website to structure and display information according to its unique business needs.Understanding how content models operate and how they affect the presentation of frontend content is the key to efficiently using AnQiCMS for website operations. ### AnQiCMS content model: Customized information blueprint The content model can be understood as the 'data structure blueprint' of various types of information on the website.

2025-11-08

How to retrieve and display all article lists under a specified category in AnQiCMS template?

When building a website with AnQiCMS, we often need to display article lists based on specific content categories, whether it is blog article categories, product categories, or news categories.This not only helps organize the content of the website, but also improves the user's browsing experience and the search engine's friendliness.AnQiCMS provides powerful and flexible template tags, making this requirement simple and intuitive.AnQiCMS's template system uses a syntax similar to the Django template engine, supported by Go language at the bottom level, ensuring the efficiency of template parsing.in the template file

2025-11-08