In the daily operation of website content, we often encounter elements that need to be dynamically updated, among which the most common is the year in the copyright statement.If it is necessary to manually modify the year at the bottom of the website every year, it not only takes time and effort, but also is prone to omissions.As a pursuit of efficient and intelligent content management system, can AnQiCMS provide us with a solution to automatically update the current year?
The answer is affirmative.AnQiCMS fully considers these subtle needs in website operation and has built-in corresponding tag functions for its template engine, allowing for the easy dynamic display of the current year.
AnQiCMS dynamic year tag:{% now %}
AnQiCMS provides a simple yet powerful tag{% now %}Used specifically to obtain and display the current real-time server time. To dynamically display the current year, you simply need to use it in the template file.{% now "2006" %}.
The '2006' here is a special string, it does not refer to a specific year, but rather a base format for date and time defined in Golang (the development language of AnQiCMS). In Golang's date and time formatting rules, '2006-01-02 15:04:05' represents a complete base time point, where:
- 2006 Represents the Year
- 01 Represents the Month
- 02 Represents the Day
- 15 Represents the Hour (24-hour format)
- 04 Represents the Minutes
- 05 represents seconds
Therefore, when you are{% now %}passed in the tag"2006"This format string will cause AnQiCMS template engine to intelligently parse it and extract the current year part for display.
Application example:
Display the current year in the copyright statement:This is the most common application scenario. For example, in the copyright information at the footer of a website:
© {% now "2006" %} 版权所有This way, every new year, the year in the website footer will be automatically updated, without manual maintenance.
Display the current complete date:If you need to display the current date, for example, in some news lists or at the top of pages:
今日日期:{% now "2006年01月02日" %}This will display 'Today's date: [current year] year [current month] month [current date] day'.
Display the current date and time:It can also be easily implemented when accuracy to seconds is required:
当前时间:{% now "2006-01-02 15:04:05" %}It will display a format similar to “Current time: 2023-10-27 10:30:15”.
By using flexibility{% now %}Labels and Golang's date formatting rules, you can almost display any current time information you want.
AnQiCMS not only provides in terms of date processing,{% now %}such a convenient real-time time tag, which also provides{{stampToDate(时间戳, "格式")}}Such a filter is used to format timestamps stored in databases (such as the publication time, update time of articles, etc.) into a readable date or time format.These two time handling methods together constitute the powerful and flexible time display capability of AnQiCMS, which can meet various complex time display needs in website content operation.
In summary, AnQiCMS's attention to detail, through the provision of simple and easy-to-use template tags, greatly enhances the automated management level of website content.This convenient dynamic year display feature allows website operators to focus more on the content itself without worrying about those cumbersome and repetitive maintenance tasks.
Common Questions (FAQ)
Q: Besides the year, can I use
{% now %}the tag to display the month, date, or week?Answer: Of course you can.{% now %}The "2006-01-02 15:04:05" used for label is the Golang standard time format. By modifying this format string, you can freely combine to display the year (2006), month (01), date (02), hour (15), minute (04), and second (05). For example, to display the current month, it can be written as{% now "01" %}Display the full date.{% now "2006年01月02日" %}You can also refer to the Golang documentation on date and time formatting to implement more complex date and time formats, such as displaying the day of the week or AM/PM, etc.Question: Which tag should I use to display the publication date of an article instead of the current date?Answer: For the release or update date of articles, products, and other content, AnQiCMS usually stores it as a timestamp. In this case, you should use
{{stampToDate(时间戳, "格式")}}This filter. For example, on the article detail page, you can use{{stampToDate(item.CreatedTime, "2006-01-02")}}to display the creation date of the article, whereitem.CreatedTimeis the article's creation timestamp field.{% now %}Labels are mainly used to display the current real-time time of the website,{{stampToDate}}and are used to format specific historical timestamps.Q:
{% now %}Does the tag require special configuration to use? Will frequent use affect the website speed?Answer:{% now %}The tag is an integrated feature of AnQiCMS template engine, which can be used directly in the template without any special configuration.It dynamically retrieves the current time during template parsing, which is a very lightweight operation and has almost no perceptible overhead on website performance.AnQiCMS is developed based on Go language, which is known for its high performance, and its template engine has also been optimized.{% now %}The tag, without worrying about its negative impact on website speed.