Manage website content in AnQi CMS and ensure its accurate and beautiful display on the frontend page, which is the core of daily operation.For each document detail page, clearly presenting the document title, publication time, and view count can not only effectively enhance user experience but also is an important part of conveying content information.AutoCMS provides powerful and flexible template tags, allowing us to easily meet these needs.

Position the document detail page template

To modify the document detail page display content, we first need to find the corresponding template file. The default template for the document detail page in the Anqi CMS template structure is usually located attemplate/{你的模板目录}/{模型table}/detail.html. For example, if your template directory isdefault, the article model (usuallyarchive) detail page template might betemplate/default/archive/detail.html.

Suggest to back up your template file before making any modifications to prevent operation errors.

Get and display the document title

The title of the document is the first step for users to understand the content topic. In the template of the document detail page, you can directly accessarchiveTo get the title, use the object because it represents the document currently being viewed.

To display the document title, you can find the appropriate position indetail.html(usually)<h1>Tag inside), then use the following code:

<h1 class="document-title">{{ archive.Title }}</h1>

archive.TitleIt will directly output the current document's title.

Show the document's publication time

The publication time of the document can help users understand the timeliness of the content. In the Anqi CMS, the creation time of the document (CreatedTime) Is stored in the form of a timestamp. To display it in a human-readable date format, we need to use.stampToDateThis is the label for formatting the timestamp.

Similarly, you can usearchiveObject retrievedCreatedTimeand usestampToDateFormatting is performed. For example, to display in the format “2023年10月27日 10:30” such as:

<span class="document-publish-time">发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}</span>

Here, "2006-01-02 15:04" is a special layout string used in Go language to define date and time formats. You can adjust this string as needed, for example, to display only the date.("2006年01月02日")Or show the full year, month, day, hour, minute, and second("2006-01-02 15:04:05").

Show the document page views

The number of views is a direct indicator of the popularity of a document. In AnQi CMS, the number of views of a document can also be obtained directly from the object.archive.

To display the document view count, you can add the code like this:

<span class="document-views">浏览:{{ archive.Views }} 次</span>

You can add units such as 'times', 'reads' before or after the number according to your preference.

Integrate all information into the template

The document title, publication time, and view count are typically displayed together at the top of the content, serving as important metadata. Below is an example of integrating the above elements intodetail.htmlTemplate example code snippet. We will also add the category and tags of the document to provide a more comprehensive information display.

`twig

{# 文档标题 #}
<h1 class="document-title">{{ archive.Title }}</h1>

<div class="document-meta">
    {# 文档所属分类 #}
    <span class="meta-item">分类:<a href="{{ archive.Category.Link }}" class="category-link">{{ archive.Category.Title }}</a></span>
    {# 文档发布时间 #}
    <span class="meta-item">发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}</span>
    {# 文档浏览量 #}
    <span class="meta-item">浏览:{{ archive.Views }} 次</span>

    {# 文档标签,通过 tagList 标签获取并循环显示 #}
    {% tagList tags with itemId=archive.Id limit="10" %}
        {% if tags %}
        <span class="meta-item">标签:
        {% for item in tags %}
            <a href="{{