Manage website content in Anqi CMS and ensure its accurate and beautiful display on the front-end page, which is the core of daily operation work.For each document detail page, clearly presenting the document title, publication time, and views can not only effectively improve user experience, but is also an important link in the communication of content information.The Anqi CMS provides powerful and flexible template tags, allowing us to easily meet these requirements.
Locate the document detail page template
To modify the display content of the document detail page, we first need to find the corresponding template file. In the template structure of Anqi CMS, the default template for the document detail page is usually located attemplate/{你的模板目录}/{模型table}/detail.htmlFor example, if your template directory isdefaultthe article model (usuallyarchivethe detail page template for it might betemplate/default/archive/detail.html.
Before making any changes, it is recommended to back up your template file to prevent any errors.
Get and display the document title
The document title is the first step for users to understand the content topic. On the document detail page template, you can directly go througharchiveAn object is used to obtain the title because it represents the document currently being viewed.
To display the document title, you can find the appropriate position indetail.html(usually)<h1>Within the tag), then use the following code:
<h1 class="document-title">{{ archive.Title }}</h1>
archive.TitleIt will directly output the current document title.
Show the document publish time
The publication time of the document can help users understand the timeliness of the content. In Anqicms, 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 usestampToDatethis label to format the timestamp.
Similarly, you can usearchiveObject retrievalCreatedTimeandstampToDateFormatting. For example, to display in the format 'October 27, 2023 10:30'.
<span class="document-publish-time">发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日 15:04") }}</span>
Here, "2006-01-02 15:04" is a special format 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 complete year, month, day, hour, minute, and second("2006-01-02 15:04:05").
Display document page views
The page views are a direct indicator of the popularity of a document. In Anqi CMS, the page views of a document can also be obtained directly fromarchivethe object.
To display the document's page views, you can add the code like this:
<span class="document-views">浏览:{{ archive.Views }} 次</span>
You can add units like 'times', 'reads' before or after numbers according to your preference.
Integrate all the information into the template.
The document's title, publication time, and view count are usually displayed together at the top of the content, serving as important metadata. Below is an example of integrating the above elements intodetail.htmlThe template contains example code snippets. 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="{{