In the daily operation of website content, we often encounter some elements that need to be dynamically updated, the most common of which is the year in the copyright statement.If you need to manually change the year at the bottom of the website every year, it not only takes time and effort but is also prone to omission.Can AnQiCMS provide us with a solution to automatically update the current year for a content management system that pursues efficiency and intelligence?

The answer is affirmative. AnQiCMS fully considers these subtle needs in website operation and has built-in corresponding tag functions for its template engine, which can easily realize the dynamic display of the current year.

AnQiCMS dynamic year tag:{% now %}

AnQiCMS provides a simple and powerful tag{% now %}This is used to obtain and display the server's current real-time time. To dynamically display the current year, you just need to use it in the template file.{% now "2006" %}Just do it.

Here "2006" is a special string, it does not refer to a specific year, but rather a base format defined in Golang (the development language of AnQiCMS). According to the Golang 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 date
  • 15 represents the hour (24-hour format)
  • 04 represents the minutes
  • 05 represents seconds

Therefore, when you are{% now %}to the tag."2006"In this format string, the AnQiCMS template engine will intelligently parse it and extract the current year part of the date for display.

Application Example:

  1. Display the current year in the copyright statement:This is the most common application scenario. For example, in the footer copyright information of a website:

    © {% now "2006" %} 版权所有
    

    This way, every new year, the year at the bottom of the website will be automatically updated without manual maintenance.

  2. Display the current full 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'.

  3. Display the current date and time:When you need to be accurate to seconds, it can also be easily achieved:

    当前时间:{% now "2006-01-02 15:04:05" %}
    

    It will display a format similar to "Current time: 2023-10-27 10:30:15".

By flexible application{% now %}Label and Golang's time formatting rules, you can almost display any current time information you want.

AnQiCMS not only provides in terms of time processing,{% now %}This convenient real-time time label also provides{{stampToDate(时间戳, "格式")}}This filter is used to format timestamps stored in databases (such as the publication time, update time of articles, etc.) into easily readable date or time formats.These two time handling methods collectively constitute the powerful and flexible time display capabilities of AnQiCMS, capable of meeting various complex time display needs in website content operation.

In summary, AnQiCMS takes into account the details, greatly enhancing the automation management level of website content by providing simple and easy-to-use template tags.This convenient dynamic year display function allows website operators to focus more on the content itself, without having to worry about those tedious and repetitive maintenance tasks.


Frequently Asked Questions (FAQ)

  1. Question: Can I use{% now %}Tags to display the month, date, or week?Answer: Of course you can.{% now %}The "2006-01-02 15:04:05" format is the Golang base time format. By modifying this format string, you can freely combine to display the year (2006), month (01), day (02), hour (15), minute (04), second (05), etc. For example, to display the current month, you can write{% now "01" %}, Display the full date as{% now "2006年01月02日" %}. You can also refer to the Golang time formatting document to implement more complex date and time formats, such as displaying the day of the week or AM/PM, etc.

  2. What tag should I use to display the publication date of an article instead of the current date?Answer: For the publication 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 creation timestamp field.{% now %}Tags are mainly used to display the current real-time time of the website, and{{stampToDate}}while used to format specific historical timestamps.

  3. Question:{% now %}Do you need special configuration for the tag to use it? Will frequent use affect the website speed?Answer:{% now %}The tag is an AnQiCMS template engine built-in feature, 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 with almost no perceptible overhead on website performance.AnQiCMS is developed based on the Go language and is known for its high performance, with its template engine also optimized.Therefore, you can safely use it where needed{% now %}Tag, without worrying about its negative impact on website speed.