As an experienced website operations expert, I know that how to flexibly display information in a content management system is crucial for improving user experience and meeting operational needs. AnQiCMS, as an efficient and easy-to-use content management system, provides powerful template tag functions, among whichstampToDateTags are a powerful tool for processing timestamps and formatting them into readable date strings.

Today, let's delve into how to make use ofstampToDateLabel, cleverly concatenate the formatted date with other text content on the page to form a complete and informative display information.


Make good use of AnQiCMSstampToDateLabel, create flexible date display information

In website operation, date and time information is everywhere, whether it is the publication time of articles, the last update time of content, or the deadline for user activities, a clear and friendly date display can greatly enhance the professionalism and user reading experience of website content. AnQi CMS fully understands this, providing us withstampToDateLabels make date formatting very simple.

However, simply formatting dates is not enough, we often need to combine this date information with fixed text, other variables, etc., to form a complete, contextually descriptive paragraph. For example, we want to displayPublished on October 27, 2023, views 1234 timesThis is not just the solitary 'October 27, 2023'. Next, let's take a look at how to achieve this flexible concatenation in Anqi CMS templates.

I.stampToDateBasic usage of tags review

First, let's briefly reviewstampToDateThe core function of the label. Its main role is to convert the timestamp stored in the database (usually a 10-digit integer) into a readable date and time format. The basic syntax is:

{{ stampToDate(时间戳, "格式") }}

The key lies in the second parameter"格式". It follows the date formatting rules specific to the Go language, such as2006-01-02 15:04:05This reference time to define various display formats. For example:

  • "2006-01-02"It will be displayed as2023-10-27
  • "2006年01月02日"It will be displayed as2023年10月27日
  • "2006/01/02 15:04"It will be displayed as2023/10/27 10:30
  • "Mon, 02 Jan 2006 15:04:05 MST"It will be displayed asFri, 27 Oct 2023 10:30:00 CST

In AnQi CMS, we often get timestamp fields from document objects(archiveor from loops, such asitem)archive.CreatedTime(creation time) andarchive.UpdatedTime(update time).

{# 假设当前处于文档详情页,archive代表当前文档对象 #}
<p>文章发布时间:{{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p>
<p>最后更新:{{ stampToDate(archive.UpdatedTime, "2006-01-02 15:04:05") }}</p>

Two, the clever combination of dates and text content

MasteredstampToDateThe basis, we can start to concatenate it with other text content.In Anqi CMS's Django-like template engine, how many natural and smooth ways are there to concatenate text and variables.

1. Embed formatted dates directly in the text

The most direct way is to embed the formatted date label directly into a fixed text description. The template engine will parse it firststampToDateLabel, then concatenate the result with the adjacent text.

For example, we want to display "Published on [date]" on the article detail page:

<p>发布于 {{ stampToDate(archive.CreatedTime, "2006年01月02日") }}</p>
{# 页面将显示:发布于 2023年10月27日 #}

If you need to include more information, such as the article title and reading volume:

`twig

文章 <strong>《{{ archive.Title }}》</strong> 发布于 
<time datetime="{{ stampToDate(archive