In the AnQi CMS, whether it is to display the detailed content of a single article or to preview multiple articles on the list page, flexibly obtaining and displaying the title, detailed content, introduction, and recommended attributes of the articles is the foundation of website operation.The design of Anqi CMS makes this process intuitive and efficient, and we mainly achieve it through the use of template tags and variable calls.

Firstly, understanding the template system of Anqi CMS is crucial. It uses a template engine syntax similar to Django, which means you will mainly use double curly braces{{变量}}Display data, as well as single curly braces and percent signs.{% 标签 %}Execute logical judgments or call specific functions.


Retrieve and display the detailed information of a single article.

When you visit a specific article page, it usually needs to display its full title, detailed content, concise introduction, and possibly recommended attributes. Anqi CMS provides an article for the current page namedarchiveThe global variable, you can directly access the various fields of the article through it.

1. Article Title (Title)

The title of the article is the soul of the content, and you can easily obtain and display it on the detail page.

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

If your template needs to obtain the title of an article with a specified ID, you can usearchiveDetailLabel, and pass in the article ID:

{# 获取ID为10的文章标题 #}
<h2>{% archiveDetail with name="Title" id="10" %}</h2>

2. Detailed Content (Content)

The core content of the article is an important part of detailed information. Safe CMS'sarchive.ContentThe field contains the full content of the article, which may include HTML tags or Markdown formatted text. To ensure that the HTML content is rendered correctly and not displayed as plain text, you need to use|safeFilter. If the content is in Markdown format, Secure CMS will automatically convert it to HTML:

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

If you want to get the detailed content of a specified ID article, you can also usearchiveDetailTags:

{# 获取ID为10的文章详细内容,并正确渲染HTML #}
<div class="other-article-content">
    {% archiveDetail articleContent with name="Content" id="10" %}
    {{articleContent|safe}}
</div>

3. Article Description

The article abstract is a brief summary of the content, which is usually used for SEO optimization on the detail page or as a quick preview of the content.The 'auto' translation is 'English'. The original value is: 安企CMS会将您在后台填写的简介原样输出。If you do not manually fill in the introduction when publishing an article, the system will automatically extract the first 150 characters of the article content as the introduction.

<p class="article-description">
    {{archive.Description}}
</p>

Similarly, retrieve the summary for a specified article ID:

{# 获取ID为10的文章简介 #}
<p class="other-article-description">
    {% archiveDetail with name="Description" id="10" %}
</p>

4. Recommended Attributes (Flag)

The auto CMS allows you to set various recommendation attributes for articles, such as headline, recommendation, slideshow, etc., which are identified by a single letter in the background (for examplehrepresents the headlinecrepresenting recommendation). In the article detail page,{{archive.Flag}}These properties will be displayed in alphabetical order.

<p class="article-flags">推荐属性:{{archive.Flag}}</p>

These properties can be used for conditional judgments in templates, such as, determining if an article is set as a headline:

{% if archive.Flag | contain: "h" %}
    <span class="flag-headline">头条</span>
{% endif %}

Get and display information from the article list

On category pages, homepages, or other list pages, you may need to display brief information of multiple articles, including titles, summaries, recommended attributes, as well as article links and thumbnails, etc.archiveListLabels come in handy.

1. English article list acquisition and traversal

archiveListTags are used to retrieve a list of articles. You can set different filtering conditions as needed, such as category ID, display quantity, sorting method, etc. The retrieved list of articles is an array object, which needs to be accessed throughforTraverse in a loop.

{% archiveList archives with type="list" limit="10" categoryId="1" %}
    {% for item in archives %}
        <div class="article-item">
            {# 这里将显示每篇文章的标题、简介、推荐属性等 #}
        </div>
    {% endfor %}
{% endarchiveList %}

In the above code,type="list"Represents getting a regular list.limit="10"Limits displaying 10 articles.categoryId="1"Then specifies the category ID of the article.archivesIs the variable name you define, representing the list of articles obtained.

2. Display the article title and link in the list.

In the list loop,item.TitleUsed to display the title of each article,item.LinkThen provided the link to the article:

<h3><a href="{{item.Link}}">{{item.Title}}</a></h3>

3. Show the summary of the articles in the list:

In the article list, we usually show summaries rather than detailed content to provide a quick preview:

<p class="item-description">{{item.Description}}</p>

4. Recommended properties in the list

Recommended properties are usually used in two ways on the list page: one is to filter articles, and the other is to display a small icon or mark next to the article.

  • Filter recommended articles from the list:If you only want to display articles set as the "recommended" attribute, you canarchiveListtag.flag="c"parameter (assuming)crepresents recommended). Please note that each callarchiveListWhen labeling, only one recommended attribute can be used for filtering.

    `twig {# Only display the article list set to the "recommended

    {% for item in recommendedArticles %}
        <div class="recommended-