How to obtain and display the title and detailed content on the article detail page?

Calendar 👁️ 52

Manage website content in Anqi CMS, the article detail page is an important window for displaying core information to visitors.Whether it is corporate news, product introduction, or technical articles, clearly presenting the title and detailed content is the key to improving user experience and information communication efficiency.AnQi CMS provides intuitive and powerful template tags, making content presentation easy and flexible.

Understand the template structure of AnQi CMS

The template files of AnQi CMS are usually stored in/templateUnder the directory, following a set of concise naming conventions. For the detail pages of articles or product documents, the default template file is usually{模型table}/detail.htmlFor example, if your content model is "article", then the detail page template might bearticle/detail.html.

In these template files, you will find that content display is mainly realized in two ways: using double curly braces{{变量}}to directly output data, as well as using single curly braces and the percent sign{% 标签 %}Come to handle logic or call functional tags. When you visit an article detail page, Anqi CMS will automatically load all the data of the current article into a namedarchiveThe global variable makes it very convenient to obtain article information.

Retrieve and display the article title

The article title is the 'face' of the content, which is usually used as the main title of the page.<h1>) and the browser tab title.

The most direct way to display the article title is to accessarchiveIn variables,TitleField:

<h1>{{archive.Title}}</h1>

This line of code will directly output the current article title.

In addition, to optimize the search engine (SEO) effect, the browser tab title of the page (<title>Labels usually need to include the article title and may also include the website name. At this time, you can use the Anqi CMS providedtdkTags:

<title>{% tdk with name="Title" siteName=true %}</title>

This code will intelligently retrieve the title of the current article and according tositeName=trueThe setting, automatically adds your website name after the title, thus enhancing the professionalism and SEO friendliness of the page. You can also usesepThe separator between the custom title and the website name.

Get and display the detailed content of the article.

The detailed content of the article is where users obtain core information, which may contain rich text, images, even videos and code. Anqi CMS will store this rich text content inContentin the field.

To display the detailed content of the article on the page, you can call it like this:

<div>{{archive.Content|safe}}</div>

There is a very important detail here:|safeFilter. Since article content is usually edited through a rich text editor, it may contain HTML tags such as<p>,<img>,<strong>and).By default, to prevent cross-site scripting (XSS) attacks, the Anqi CMS template engine will escape all output content, which means<p>May be displayed as&lt;p&gt;Causes the content to be displayed as raw code instead of formatted style.

Use|safeThe filter explicitly tells the template engine that this part of the content is 'safe', and does not need to be escaped, so that the browser can correctly parse and display the well-formatted article content.

If your article content is written using a Markdown editor and you want the front-end to automatically convert it to HTML rendering, you canarchiveDetailthe tag withrender=trueparameters. At the same time, if the article contains images and you want to implement lazy loading of images, you can uselazy="data-src"these parameters in conjunction with the front-end lazy loading library.

{# 使用archiveDetail标签的完整示例,并考虑Markdown渲染和图片懒加载 #}
<div>
    {% archiveDetail articleContent with name="Content" render=true lazy="data-src" %}
    {{articleContent|safe}}
</div>

integrate more article information

A complete article detail page usually is not just the title and content.You may also need to display auxiliary information such as the release time, views, and article description.This data can also be directly fromarchivefrom the variable.

The following is a comprehensive example of how to combine display of title, content, publication time, page views, and article description on an article detail page:

`html {% extends 'base.html' %} {# Inherit the basic layout to ensure consistency of the page structure #}

{% block title %}

{# 浏览器标签页标题,包含文章标题和网站名称 #}
<title>{% tdk with name="Title" siteName=true %}</title>

{% endblock %}

{% block content %}

{# 主标题,通常为文章标题 #}
<h1 class="article-title">{{archive.Title}}</h1>

<div class="article-meta">
    {# 显示发布时间,使用stampToDate过滤器格式化为可读日期 #}
    <span class="publish-time">发布时间:{{stampToDate(archive.CreatedTime, "2006-01-02")}}</span>
    {# 显示浏览量 #}
    <span class="views">浏览量:{{archive.Views}} 次</span>
    {# 显示文章描述(如果存在) #}
    {% if archive.Description %}
    <p class="article-description">{{archive.Description}}</p>
    {% endif %}
</div>

<div class="article-content">
    {# 显示文章详细内容,使用safe过滤器确保HTML

Related articles

How to declare a temporary variable in AnQiCMS template and use it to display content, improving template flexibility?

In the template creation of Anqi CMS, we often need to display various dynamic content.It is crucial to be proficient in using temporary variables to make templates more flexible and code more concise.The Anqi CMS template engine provides powerful functionality for declaring temporary variables, which helps us better organize and process data, thereby improving the efficiency and maintainability of content display.### Understanding the Value of Temporary Variables Imagine that you need to display processed data at multiple locations on the page, or that a piece of data is used repeatedly in conditional judgments, or that data obtained from a tag needs to be further processed before it can be presented

2025-11-08

How to optimize page layout and content display by using the template inheritance (`extends`) tag?

In AnQiCMS, templates are the foundation for building the appearance and layout of a website.A well-designed template not only makes the website look professional and beautiful, but also greatly enhances the efficiency of content operation and the convenience of website maintenance.Among many powerful template tags, the `extends` (template inheritance) tag is undoubtedly one of the key tools for optimizing page layout and content display.It can help us build a unified and flexible website structure, making content operation and frontend development more effortless.### Understanding `extends`: The core of template inheritance `extends`

2025-11-08

How to define and call the `macro` tag in AnQiCMS template to display reusable code blocks?

AnQiCMS provides a flexible and powerful template system, making the display of website content efficient and beautiful.In template development, in order to enhance the reusability and maintainability of code, we often encounter the need to encapsulate a commonly used code snippet so that it can be called in different places.This is when the `macro` tag becomes the key tool to achieve this goal.It allows us to define reusable code blocks, like functions in programming languages.Why do we need the `macro` tag?

2025-11-08

How to avoid extra blank lines when template logical tags (such as if, for) are rendered on the page?

When developing templates in AnQiCMS, we often find that even though the template code itself looks neat, the final rendered HTML page may still contain some unexpected blank lines.These blank lines do not affect the page function, but may make the HTML source code look less tidy, and even in some extreme optimization scenarios, it may bring a slight increase in file size.For users who pursue code aesthetics and concise output, how to effectively avoid these redundant blank lines is a topic worth discussing.

2025-11-08

How to correctly display images in the article content of AnQiCMS templates and support lazy loading of images?

In content operation, exquisite images can significantly enhance the attractiveness and reading experience of articles.However, image files are often large, and if not handled properly, they may slow down page loading speed, affect user experience, and even search engine rankings.AnQiCMS fully understands this, providing a flexible way to correctly display images in article content within templates, and supports lazy loading of images to balance aesthetics and performance.### Core: Display images in article content In the AnQiCMS template, to obtain the main content of the article, we mainly rely on `{%

2025-11-08

How to display the name, link, and hierarchy of the article category on the article detail page?

AnQi CMS is a flexible and efficient content management system that provides great freedom in content display.For a website, the article detail page not only needs to display the content of the article itself, but also the name, link, and even the hierarchical relationship of the category it belongs to, which are all important components for improving user experience, optimizing website structure, and promoting SEO.Clear categorization information can help users quickly understand the positioning of the article, facilitate their further browsing of related content, and also enable search engines to better crawl and understand the structure of the website.Next, we will discuss how to use the Anqi CMS article detail page

2025-11-08

How to retrieve and display the publish time, update time, view count, and comment count of an article?

## Mastering AnQi CMS: A Comprehensive Guide to Article Publishing and Interactive Data Display In website operation, clearly displaying the publication and update time of articles, popularity (page views), and reader feedback (number of comments) can not only effectively improve user experience but also enhance the authority and timeliness of the content.AnQiCMS (AnQiCMS) relies on its flexible template tag system to make the acquisition and display of this key information simple and efficient.This article will explain in detail how to implement these functions in Anqi CMS.### One

2025-11-08

How to display the cover image, thumbnail, or group image of an article on the article detail page?

In Anqi CMS, adding images to the article detail page is an important link to improve the attractiveness of the content and the reading experience, whether it is the cover main image, thumbnail, or multiple group images.Anqi CMS provides a flexible and intuitive way to manage and display these image resources, allowing you to easily achieve diverse visual presentations. ### The Flexible Use of Article Cover Image and Thumbnail In the article detail page, the cover image (Logo) and thumbnail (Thumb) are the most common image elements.They are usually used to represent the main visual content of an article and are widely used on list pages

2025-11-08