How to display the complete article content on the article detail page, including lazy-loaded images?

Calendar 👁️ 66

AnQi CMS: How to elegantly display full content and lazy loading images on the article detail page

In website content operation, the article detail page is an important touchpoint for users to obtain information and deeply understand the brand and product.A well-designed, fast-loading, and comprehensive article detail page that can greatly enhance user experience and effectively assist in SEO optimization.For users of Anqi CMS, taking full advantage of its powerful template tag system can easily achieve the complete presentation of article content, and combine with modern web technology to implement lazy loading of images, making your website both beautiful and efficient.

Core: Understanding the structure of the article detail page

In AnQi CMS, the full content of the article, including text, images, videos, and other multimedia elements, is stored in the "document content" field you edited when publishing the article.When the user visits the article detail page, we need to extract the content stored in the database through template tags and render it in the browser.At the same time, it is particularly important to introduce a lazy loading mechanism to optimize the page loading speed, especially for articles with many images.

Step 1: Prepare your article detail template

The AnqiCMS template follows a clear directory structure and naming conventions. Usually, the template file for the article detail page is located under the current template theme.{模型table}/detail.htmlFor examplearchive/detail.htmlorproduct/detail.html. If you have a special category or document that requires a unique layout, you can also specify the use of a custom template in the background, such asdownload.html.

First, make sure yourdetail.htmlThe file inherits the basic template to reuse the common header, footer, and styles of the website:

{% extends 'base.html' %}

{% block content %}
    {# 在这里编写文章详情页的具体内容 #}
{% endblock %}

Step two: Call the key tags of the full content of the article ——archiveDetail

AnQi CMS providesarchiveDetailTag to get the detailed information of the article (document). To display the full content of the article, you need to usename="Content"Parameter.

{% archiveDetail articleContent with name="Content" %}
    {{ articleContent|safe }}
{% endarchiveDetail %}

Here are some key points to note:

  1. name="Content": This is the parameter specified to get the main content of the article.
  2. archiveContentThis is a custom variable name used to store the article content obtained. You can customize it according to your preference.
  3. |safeFilter:This step is crucial.. The article content usually includes HTML tags (such as<p>,<img>,<strong>etc.), if not added|safeThe filter, Anqi CMS defaults to escaping all HTML tags for security reasons, resulting in a display of a lot of code instead of well-formatted content on the page.|safeTell the template engine that this content is safe HTML and can be rendered directly.

Handle image lazy loading

To improve page loading speed, especially for articles with many images, lazy loading (Lazy Load) is a very effective optimization method. Anqi CMS'sarchiveDetailThe tag is built-in with support for lazy loading of image attributes.

You can add tolazy="data-src"Parameters, so that the system can automatically convert the content of the article.<img>label'ssrcproperties todata-srcProperty.

{% archiveDetail articleContent with name="Content" lazy="data-src" %}
    {{ articleContent|safe }}
{% endarchiveDetail %}

After you set it like this, Anqi CMS will replace all image tags in the article content (such as<img src="https://en.anqicms.com/uploads/image.jpg" />) to<img data-src="https://en.anqicms.com/uploads/image.jpg" />.

Please note:lazy="data-src"It is just to modify the attribute name of the image. To truly implement lazy loading, you also need to introduce the corresponding JavaScript lazy loading library on the front end and initialize it according to the requirements of the library, so that it can identifydata-src(or any specified attribute) and load on demand. Most lazy loading libraries on the market support this.data-srcProperty.

Rendering of Markdown content

If your article content is written in Markdown format and the Markdown editor is enabled in the background "Global Settings" -> "Content Settings", then you may need to handle it extra when calling content in the template to ensure it is rendered correctly as HTML.

archiveDetailTags providedrender=trueThe parameter automatically converts Markdown content to HTML:

{% archiveDetail articleContent with name="Content" lazy="data-src" render=true %}
    {{ articleContent|safe }}
{% endarchiveDetail %}

This way, your Markdown content can be correctly parsed and rendered on the page. At the same time, you also need to introduce the CSS styles and possible JS libraries required for Markdown rendering, such ashelp-markdown.mdmentionedgithub-markdown-css.

Step 3: Enrich the other information on the article detail page

A complete article detail page not only needs to show the content itself, but also needs to display the title, publication time, category, tags, reading volume, and other auxiliary information, which can also be displayed througharchiveDetailTag or other related tags to obtain.

  • Article title:{% archiveDetail with name="Title" %}
  • Release Time:{{stampToDate(archive.CreatedTime, "2006-01-02")}}
  • Category:{% categoryDetail with name='Title' %}
  • Tag: Use.tagListLoop tags to obtain all tags associated with the article.
  • view count:{% archiveDetail with name="Views" %}
  • Custom parameterIf your content model defines additional fields, you can usearchiveParamsLoop tag display.

Integration and Optimization: A complete detail page fragment

Integrate the above elements, and the core code of an article detail page with complete content display and lazy loading function is roughly as follows:

"twig {% extends 'base.html' %}"

{% block content %}

<article class="article-detail-container">
    {# 文章标题 #}
    <h1 class="article-title">{% archiveDetail with name="Title" %}</h1>

    {# 文章元信息:分类、时间、浏览量 #}
    <div class="article-meta">
        <span>分类:<a href="{% categoryDetail with name='Link' %}">{% categoryDetail with name='Title' %}</a></span>
        <span>发布于:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
        <span>阅读量:{% archiveDetail with name="Views" %}</span>
    </div>

    {# 文章标签 #}
    <div class="article-tags">
        {% tagList tags with itemId=archive.Id %}
            {% for item in tags %}
                <a href="{{item.Link}}" class="tag-item">{{item.Title}}</a>
            {% endfor %}
        {% endtagList %}
    </div>

    {# 文章主体内容:包含懒加载和Markdown渲染 #}
    <div class="article-content markdown-body"> {# 假设您已引入github-markdown-css,并使用markdown-body类 #}
        {% archiveDetail articleContent with name="Content" lazy="data-src" render=true %}
            {{ articleContent|safe }}
        {% endarchiveDetail %}
    </div>

    {# 更多自定义参数(如果需要) #}
    <div class="article-custom-params">
        {% archiveParams params %}
            {% for item in params %}
                <p><strong>{{item.Name}}:</strong>{{item.Value}}</p>
            {% endfor %}
        {% endarchiveParams %}
    </div>

    {# 上一篇/下一篇文章导航 #}
    <div class="article-nav">
        {% prevArchive prev %}
            {% if prev %}
                <a href="{{prev.Link}}" class="prev-article">上一篇:{{prev.Title}}</a>
            {% else %}
                <span class="prev-article-none">没有了</span>
            {% endif %}
        {% endprevArchive %}
        {% nextArchive next %}
            {% if next %}
                <a href="{{next.Link}}"

Related articles

How to display a document list based on different conditions (such as categories, recommended properties)?

In Anqi CMS, flexibly displaying website content is the key to improving user experience and meeting operational needs.Whether based on the category of the article or the recommended attributes of the content, the system provides powerful and easy-to-use template tags that allow you to easily customize the display of the document list. ### Core Tool: `archiveList` Document List Tag The core tool used in AnQi CMS to control the display of document lists is the `archiveList` tag.It allows you to filter, sort, and limit the number of displayed documents based on multiple conditions

2025-11-08

How to get and display all the content and associated images of a specific single page?

In Anqi CMS, a single page is an important part of the website content structure, such as "About Us", "Contact Information", and so on.Effectively acquire and display all the content of these single pages and associated images, which is crucial for the communication and visual expression of the website.Aanqi CMS provides an intuitive backend management and flexible template tags, making this process very convenient. ### Easily set up single page content and images in the background First, we need to create and edit single page content in the Anqi CMS backend management system. This is usually performed under the 'Page Resources' section in the 'Page Management' module

2025-11-08

How to display all or part of a single-page list on a website?

In website operations, we often need to display some independent, fixed-content pages, such as 'About Us', 'Contact Information', or some policy descriptions, etc.In Anqi CMS, these are called "single pages". Effective management and presentation of these single pages not only makes the website structure clearer but also enhances the user experience.Next, we will discuss how to flexibly display all or part of a single-page list on a website.### **Understanding the Creation and Management of Single Pages (Backend Operations)** Before Starting the Frontend Display

2025-11-08

How to retrieve and display detailed information of a specific category (such as description, Banner image)?

In Anqi CMS, it is crucial to flexibly obtain and display detailed information about categories, such as descriptions, Banner images, or thumbnails, which is essential for building a website rich in content and visually appealing.Whether it is necessary to display a brief introduction on the category list page or to reference the promotional picture of a specific category on a specific page, Anqi CMS provides intuitive and powerful template tags to help you meet these needs. To get detailed information about the category, we mainly rely on the `categoryDetail` template tag.This tag is specifically designed to extract data for each category

2025-11-08

How to display mathematical formulas and flowcharts with Markdown in AnQiCMS?

In content operations, sometimes we need to display complex mathematical formulas or clear flowcharts, especially in technical articles, data reports, or educational content.AnQiCMS with its powerful Markdown editor, provides us with the convenience to meet this requirement.By simple configuration and importing the necessary library files, you can perfectly present these professional contents on the website front-end.### Enable AnQiCMS Markdown Editor Firstly, let AnQiCMS recognize and handle Markdown formatted content

2025-11-08

How to display the links to the previous and next articles on the document detail page?

When browsing website content, users often want to be able to navigate easily between related articles.For example, after reading a news article or tutorial, you can quickly click to go to the "previous" or "next" article to maintain the continuity of reading.This not only improves user experience and reduces the bounce rate, but also has a positive effect on the internal link structure of the website and search engine optimization (SEO).AnQiCMS (AnQiCMS) is an efficient content management system that provides a very simple and intuitive way to implement this function.We do not need complex backend programming

2025-11-08

How to display a list of related articles below the article detail page?

In website operation, the list of "related articles" at the bottom of the article detail page is an important function to enhance user experience, increase page views (PV), and prolong the time users stay on the site.It can guide users to discover more interesting content, thereby enhancing the overall stickiness of the website, and also has a positive effect on search engine optimization (SEO).To implement this feature in AnQi CMS, it benefits from its flexible template system and powerful tag functions, making the entire process intuitive and efficient.### One, understand the call mechanism of "related articles" The template tags of AnQi CMS are the core of realizing various functions

2025-11-08

How to display custom parameters on an article or product detail page?

In website operation, adding personalized information to articles or product detail pages is the key to improving content professionalism and user experience.AnQiCMS (AnQiCMS) fully understands this need and provides powerful customizable parameter functions, allowing us to flexibly add and display the required information according to different content types. Imagine you publish a technical article, in addition to the title and content, you also want to display unique attributes such as "author", "publish date", "technology stack", and so on; Or maybe, you are selling a product, in addition to the usual name, price, and description, you also want to highlight the "color"

2025-11-08