How to display article title and content in AnQiCMS template?

Calendar 👁️ 71

In AnQi CMS, whether it is to display the detailed content of a single article or to present article titles and abstracts on the list page, it benefits from its flexible and easy-to-understand template tag system.AnQiCMS uses a syntax similar to the Django template engine, making content calls intuitive and efficient.

Basic template: the bridge of content presentation

In AnQiCMS, you will find that all template files are suffixed with.htmland are uniformly stored in the template folder you choose (for example/template/default/The core of the template engine lies in two types of markers:

  • double curly braces{{ 变量名 }}Used to directly output the content of variables.
  • single curly braces and percent signs{% 标签名 参数 %}: Used to implement logical control, such as conditional judgments (if/else), loops (for), and calling various built-in functional tags.

Understood these two basic tags, we can then start to explore how to display the title and content of articles in the AnQiCMS template.

Display the title and content of a single article (details page)

When you visit the details page of a specific article (for examplearticle/123.html),AnQiCMS will intelligently provide all the information of the current article asarchivean object to the template. This means you can directly accessarchivevarious properties of the article through the object.

To display the article title, you can use the following method:

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

And to display the detailed content of an article, the content usually includes HTML tags (such as paragraphs, images, bold, etc.), in order to ensure that these HTML tags are parsed correctly by the browser rather than displayed as plain text, we need to use|safeFilter:

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

|safeThe filter tells the template engine that this content is safe HTML code and can be output directly without escaping. If your article content was written using a Markdown editor and you want it to be rendered as HTML on the front end, you can also explicitly userender=trueparameters:

<div class="article-content">
    {% archiveDetail archiveContent with name="Content" render=true %}{{ archiveContent|safe }}
</div>

In addition, you can also utilizearchiveDetailTag to control the display of content more finely, or to call the content of the specified ID at other locations on non-article detail pages:

{# 在文章详情页,直接使用即可 #}
<h1>{% archiveDetail with name="Title" %}</h1>
<p>发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p>
<div class="article-body">
    {% archiveDetail articleFullContent with name="Content" lazy="data-src" %}{{ articleFullContent|safe }}
</div>

{# 在其他页面调用ID为1的文章标题和内容 #}
<h2>{% archiveDetail with name="Title" id="1" %}</h2>
<p>{% archiveDetail with name="Description" id="1" %}</p>

In the above example,stampToDateTags are used to format the Unix timestamp of an article into a readable date,lazy="data-src"It is a parameter for lazy loading images in the content, making image loading more optimized.

Show the title and summary of the article list (list page)

On the article list page (for example, the category list page or search results page), we usually display brief information about multiple articles, such as titles, abstracts, and links, rather than the full content of the articles. AnQiCMS providesarchiveListTag to achieve this requirement.

archiveListTags allow you to get a list of articles based on various conditions such as categories, modules, and recommended attributes. After obtaining the list of articles, you need to usefora loop to iterate over each article.

The following is a common usage to display a list of article titles, links, and summaries:

<ul class="article-list">
    {% archiveList articles with type="page" moduleId="1" limit="10" %} {# 获取文章模型ID为1,每页10条的列表 #}
        {% for item in articles %}
            <li>
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                <p class="summary">{{ item.Description }}</p>
                <span class="date">发布于:{{ stampToDate(item.CreatedTime, "2006-01-02") }}</span>
            </li>
        {% empty %}
            <li>暂无文章可显示。</li>
        {% endfor %}
    {% endarchiveList %}
</ul>

In this example:

  • archiveListA label has obtained a namedarticlescollection of articles.type="page"indicates that this is a paginated list,moduleId="1"specifies the model ID of the article,limit="10"It limited the number of articles displayed per page.
  • {% for item in articles %}Looped througharticlesEach article in the collection, and the current article object is named.item.
  • {{ item.Link }}/{{ item.Title }}and{{ item.Description }}Used to output the link, title, and automatically generated summary of the article.
  • {% empty %}the block will bearticlesThe collection is displayed when empty, providing a friendly user prompt.
  • stampToDate(item.CreatedTime, "2006-01-02")Also used to format the creation time of the article.

By combining these tags, you can flexibly and efficiently display various article content in the AnQiCMS template, meeting the display needs of different pages.Mastering these basic usages will make your website content management twice as efficient.

Frequently Asked Questions (FAQ)

  1. Why am I outputting directly in the template.{{ archive.Content }}The HTML tags in the article content were not parsed and were displayed as is?This is because the AnQiCMS template engine, for security reasons, defaults to escaping all output content. If you confirm that the content is safe HTML code, you need to use|safeA filter to indicate that the template engine should skip escaping, for example{{ archive.Content|safe }}.

  2. How to display a brief summary of the article on the article list page instead of the full article content?You can use it on the article list page:{{ item.Description }}To display the summary of the article.DescriptionFields are typically automatically extracted by the system from the article content at the time of publishing or manually filled in by the editor. If you need to customize the length of the summary, you can usetruncatecharsortruncatewordsFiltering is performed.

  3. If I have an article ID but it is not on the article detail page, how can I call the title and content of this specific article?You can usearchiveDetailLabel and pass in.idSpecify the article ID with parameters, for example{% archiveDetail articleData with name="Title" id="文章ID" %}{{ articleData }}To get the title, or{% archiveDetail articleContent with name="Content" id="文章ID" %}{{ articleContent|safe }}To get and display the content.

Related articles

The `render` filter of AnQi CMS can render which specific string formats into HTML output besides Markdown?

In the daily use of the content management system, we often need to display the stored plain text content in rich HTML form to users.AnQiCMS (AnQiCMS) provides powerful template rendering capabilities, where the `render` filter is one of the key tools for handling such requirements.Many users may already know that it can convert Markdown-formatted text to HTML, so what specific formats can this `render` filter handle besides Markdown?

2025-11-08

How to flexibly remove spaces or specified characters from the beginning or end of a string in AnQi CMS using `trim`, `trimLeft`, and `trimRight` filters?

During website content operation, we often encounter the need to process strings, such as cleaning user input, unifying display formats, or optimizing search engine inclusion (SEO), etc.AnQiCMS (AnQiCMS) powerful template engine provides a variety of practical filters, among which `trim`, `trimLeft`, and `trimRight` are powerful assistants for us to flexibly delete extra spaces or specified characters from the beginning or end of strings or in specific directions.### `trim` filter: bidirectional trimming

2025-11-08

How to implement batch string replacement with the `replace` filter in AnQi CMS, especially when performing SEO keyword optimization?

AnQiCMS, with its flexible and efficient features, has become a powerful assistant for many content operators to improve their website performance.In website operation, especially when performing SEO keyword optimization, the accuracy and timeliness of content are crucial.Today, let's delve deeply into a seemingly simple yet powerful tool in Anqi CMS—the `replace` filter, and how to巧妙运用it巧妙运用it effectively to achieve batch replacement of strings, thereby making your SEO keyword optimization work twice as effective.### One

2025-11-08

How to use the `repeat` filter in Anqi CMS template to quickly generate repeated placeholders or decorative strings?

In AnQi CMS template design, flexibly using various filters (Filter) is the key to improving template performance and development efficiency.Among them, the `repeat` filter provides a very convenient solution for quickly generating repetitive placeholders or decorative strings with its concise characteristics.`repeat` filter, as the name implies, is mainly used to repeat a specified string or variable content according to the number of times set.

2025-11-08

How to customize the URL structure of the article detail page in AnQiCMS for optimized display?

In website operation, a clear and meaningful URL structure not only helps search engines better understand and capture your content, but also significantly improves the browsing experience of users.AnQiCMS knows this and therefore provides flexible and powerful features that allow you to easily customize the URL structure of the article detail page. Let's take a deeper look at how AnQiCMS can help you achieve this goal, creating a more advantageous URL for your website.Why is it important to customize URL structure?Before delving into the features of AnQiCMS

2025-11-08

How to use AnQiCMS content model to customize fields and display them on the front end?

In website operation, we often encounter such situations: the standard 'article' or 'product' content type cannot fully meet our unique business needs.For example, you may need to post "real estate information", which requires special fields such as "house type", "area", "orientation", etc.Or you are running a "recruitment platform" and need "job title", "location", "salary range", and "skills required" and so on.At this moment, the flexible content model and custom field function of AnQiCMS are particularly important, as they can help us create a content structure that perfectly fits the business

2025-11-08

How to implement pagination display of the article list in AnQiCMS?

In AnQiCMS, the pagination display of the article list is a very common and important function in content operation.It not only makes it easier for visitors to browse a large amount of content, improve user experience, but also has an indispensable role in search engine optimization (SEO), which can help search engines better crawl and index website content.AnQiCMS as an efficient and customizable content management system took this into full consideration from the beginning, therefore the pagination function of the article list is very intuitive and flexible.This is mainly due to its powerful template tag system

2025-11-08

How to get and display the list of articles under a specified category in AnQiCMS?

To retrieve and display a list of articles under a specified category in AnQiCMS is a very common requirement in website content operation.No matter if you want to display the latest articles of a specific category on the homepage or aggregate all the content of a special topic on an independent page, AnQiCMS's powerful template tag system can help you easily achieve it.AnQiCMS's template engine syntax is similar to Django, allowing you to directly call backend data in HTML templates using concise and clear tags and variables.This article will guide you on how to use `archiveList`

2025-11-08