Does AnQiCMS provide a feature for dynamically displaying the current year tag?

Calendar 👁️ 83

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.

Related articles

How to safely output the article content containing HTML tags in a template, preventing XSS attacks while maintaining the format?

In website content operation, we often need to publish articles containing images, links, paragraph styles, and other rich formats.AnQiCMS (AnQiCMS) is a powerful content management system with a flexible template engine that can help us easily display these contents.However, while enjoying the convenience, we must also pay attention to a core issue: how to safely output the article content with HTML tags in the template, while maintaining its original beautiful format and effectively preventing potential cross-site scripting (XSS) attacks

2025-11-09

How to display the AnQiCMS comment list on the front end and show the reply level and like count?

In website content operation, user comments are an important aspect for building community atmosphere, enhancing content interaction, and collecting user feedback.AnQiCMS (AnQiCMS) fully understands this and provides a powerful and flexible comment management feature, and through its powerful template engine, allows you to easily display comments on the front-end page, including reply levels and like counts and other detailed information.Next, we will together learn how to clearly present these comments on your website using the template tags and fields of Anqi CMS.### AnQiCMS

2025-11-09

How to use a for loop in AnQiCMS template and control the special display style of the first or last item in the loop?

When building a website, we often need to finely control the elements in the list, especially when displaying list data, setting a unique style for the first or last item in the list is a common requirement.For example, you may want the first product image in the list to be larger, or to not display the separator at the end of the news list.AnQiCMS's powerful template system provides an intuitive and flexible way to meet such needs.AnQiCMS's template system is based on Go language, but its syntax style is very similar to the Django template engine

2025-11-09

Does AnQiCMS support automatically converting uploaded JPG/PNG images to WebP format to improve page loading speed?

The importance of page loading speed in website operation is self-evident.A fast-loading website not only improves user experience and reduces bounce rate, but is also one of the key factors in search engine optimization (SEO).Images are an important part of web content, and their loading efficiency directly affects the overall performance of the page.Therefore, converting traditional JPG/PNG images to the smaller and more efficient WebP format has become the mainstream trend of website optimization.When using the AnQiCMS website management, if you have ever been confused about how to automatically optimize the uploaded images

2025-11-09

How to set up scheduled article publishing in AnQiCMS to achieve automated content display?

In today's internet age where content is king, the continuous update and efficient operation of website content is the key to attracting and retaining users.However, manual timed release is not only time-consuming and labor-intensive, but may also miss the**release opportunity due to negligence.AnQiCMS addresses this pain point by building a convenient scheduled publishing function, which helps us easily achieve automated content display.Why choose scheduled publication to achieve content automation?Timely publishing is not only a tool to improve efficiency, but also an indispensable part of content operation strategy.The benefits it brings are obvious: *

2025-11-09

How to display custom contact information on the website frontend, such as WhatsApp or Facebook links?

In today's digital age, allowing customers to easily find and contact you is the cornerstone of any successful website.Whether it is to provide customer support, promote sales, or build community interaction, clear and visible contact information is crucial. 幸运的是,AnQi CMS provides a set of intuitive and powerful features that allow you to easily display various custom contact methods on your website front-end, such as WhatsApp or Facebook links, ensuring that your customers can always communicate with you conveniently.Next, we will step by step introduce how to achieve this goal in Anqi CMS

2025-11-09

How to implement pagination functionality in AnQiCMS

For any website that carries a large amount of content, how to efficiently and friendly display this content is undoubtedly one of the keys to successful operation.When there are a large number of articles, products, tag pages, and other content, it is obviously unrealistic to pile them all on one page. This not only slows down the loading speed but also makes it difficult for users to find the information they need.At this time, the pagination function is particularly important. In AnQiCMS, implementing pagination is quite intuitive and flexible.It cleverly combines the acquisition of content lists with the display of pagination navigation, making the organization and presentation of website content both beautiful and efficient.###

2025-11-09

How to safely escape URL parameters in AnQiCMS templates to avoid potential risks?

When building and operating a website, URL (Uniform Resource Locator) parameters play a crucial role, helping us to achieve dynamic content display, filtering, and navigation functions.However, improper handling of URL parameters may also become a major security vulnerability for websites.This article will deeply explore how to safely escape URL parameters in the AnQiCMS template to effectively avoid potential risks.### The security risks of URL parameters should not be overlooked URL parameters usually carry user input or data generated by the system, such as search keywords, category ID

2025-11-09