As an experienced website operation expert, I have accumulated rich experience in the practical application of AnQiCMS, especially I have a deep impression on the flexible use of template tags. Today, let's delve into it in depth.stampToDateThis commonly used tag, when it is called in the AnQiCMS multi-site environment, are there some special points that need to be paid attention to.

AnQiCMS is an efficient and customizable enterprise-level content management system, and its multi-site management function is one of its core advantages.It allows users to manage multiple independent sites on a unified backend, whether it is a brand sub-site, regional portal, or multilingual content, it can be managed properly.Under this complex and flexible architecture, the application of each tag may produce subtle differences due to different data sources or display requirements.

UnderstandingstampToDateThe essence of tags.

First, let's reviewstampToDateThe basic function of the tag. According to the AnQiCMS document,stampToDateIt is an auxiliary tag used to format timestamps, with a concise syntax:{{stampToDate(时间戳, "格式")}}. The 'timestamp' is usually a 10-digit Unix timestamp, and the 'format' follows the special time formatting convention of Golang (Go language), for example,"2006-01-02"Represents year-month-date,"15:04:05"Indicates hours, minutes, and seconds, etc.

In essence,stampToDateIs a pureData formatting toolIt is not a data acquisition tool. It receives an existing timestamp (usually the creation or update time of the content read from the database) and then converts it into a human-readable date or time string according to the format specified by the developer.This meansstampToDateIt does not care where the timestamp is obtained from, it only needs to be converted according to the established rules.

in a multi-site environmentstampToDatespecial considerations

SincestampToDateDoes it not have any special considerations in a multi-site environment if it does not involve the selection of data sources?It is not like that. Its uniqueness does not lie in the parameters or syntax of the tag itself, but inData sourceanddisplay strategyconsiderations on the platform.

1. Clarity of data source

In the multi-site architecture of AnQiCMS, the data of each site is relatively independent. When we use for examplearchiveList/categoryList/archiveDetailWhen tags are used to retrieve article or category data, these tags usually contain an optionalsiteIdparameter. The purpose of this parameter is to allow you to in a site template,Call data from another site.

For example, you might want to display the latest articles from all child sites in a template on a main site. In this case, you will traverse differentsiteIdto callarchiveListOnce a content object of a specific site (whether it is the current site or another site) is obtained, for examplearchive(document object), its internalCreatedTimeorUpdatedTimeThe field is a standard timestamp. At this point, you can pass this timestamp without any obstaclesstampToDateFormat:{{stampToDate(archive.CreatedTime, "2006-01-02 15:04")}}.

So, the core isThe source of the timestamp. As long as you ensure you have obtained the correct site data object,stampToDateit will work normally. It will not show any 'abnormal' behavior due to timestamps from different sites.

2. Cross-site time format localization and consistency

This isstampToDateThe core that truly needs 'special attention' in a multi-site environment. AlthoughstampToDateIt provides flexible formatting capabilities, but it does not havelocalization (Localization) capabilitiesThat is to say, it will not automatically adjust the output date format according to the language or regional settings of the current site.

Assuming you manage two sites: one for Chinese users (language: Chinese), and the other for European users (language: English).

  • On Chinese sites, you may want to use the date format 'January 15, 2023'.
  • On English sites, you may want the date format to be "15 January 2023" or "15/01/2023".

If you simply use the template in both site{{stampToDate(item.CreatedTime, "2006-01-02")}}Then both sites will output the unified format of "2023-01-15".This may be acceptable for some scenarios, but for websites that pursue user experience and localization of content, such a unified format may not conform to users' reading habits.

To solve this problem, as a website operator or template developer, you need to adoptProactive strategies:

  • Template customization:The most direct way is to create or modify the corresponding template file for each site with different languages or regions, and manually set different Golang date format strings. For example, the Chinese template uses"2006年01月02日"Used in English template."02 January 2006".
  • Use system configuration:AnQiCMS providessystemTag to obtain background configuration information, you can define a special date format string parameter for each site in the "Global Function Settings" or "Custom Parameter Settings" on the background (for example,"DateFormat_Zh"/"DateFormat_En")。Then, pass it through the template{% system with name="DateFormat_Zh" %}to get this format string and then pass it tostampToDate. When the site switches, the template adjusts dynamically according to the different format strings obtained.This is undoubtedly a more elegant and maintainable solution, especially when you have a large number of sites.

In summary,stampToDateThe tag itself does not have any new parameters or behavior changes in the multi-site environment of AnQiCMS. Its 'special precautions' mainly include: ensure that you obtain the timestamp from the correct data source, as well as according to the localization needs of different sites,Proactively design and apply the corresponding date format stringThis requires operators and developers to carefully plan the display of date and time in template design and content management to provide a better user experience.


Frequently Asked Questions (FAQ)

Q1:stampToDateIs the label needed?siteIdParameter to specify from which site to get the timestamp? A1:Not required.stampToDateThe tag is a pure formatting tool that only accepts a timestamp value and a format string for conversion. It itself is not responsible for data retrieval, therefore it does not needsiteIdThe timestamp is usually obtained by other data and tagged (such asarchiveList/archiveDetail) from the data object of a specific site.

Q2: If my AnQiCMS has deployed multiple language sites,stampToDatewill the tags automatically output the corresponding date format based on the site language? A2:will not automatically.stampToDateThe label does not have the function of automatic localization of date formats. It simply converts according to the Golang format string you provide.In order to display different date formats on different language sites, you need to specify manually or through the corresponding site template.systemConfigure different date format strings for labels.

Q3: Can I set a global date format in the AnQiCMS backend and have all sites automatically apply it? A3:Can. You can add custom parameters in the "Global Function Settings" of AnQiCMS backend, for example named "DefaultDateFormat", and set a default Golang date format string.Then through the templates on all sites,{% system with name="DefaultDateFormat" %}Get and apply this format. But please note that if some sites require special localization formats, you still need to customize templates or set specific custom parameters for them.