As an experienced website operations expert, I have accumulated rich experience in the practical application of AnQiCMS, especially the flexible use of template tags, which deeply impressed me. Today, let's delve into this topic in depth.stampToDateThis common tag, when it is called in the AnQiCMS multi-site environment, are there some special points that need to be paid attention to?
AnQiCMS as an efficient and customizable enterprise-level content management system, 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's brand sub-sites, regional portals, or multi-language content, all can be managed properly.Under this complex and flexible architecture, the application of each tag may produce subtle differences due to the diversity of data sources or display requirements.
UnderstandingstampToDateThe essence of tags
First, let's take a look back atstampToDateThe basic function of the label. According to the AnQiCMS document,stampToDateIt is an auxiliary label used for formatting timestamps, its syntax is concise and clear:{{stampToDate(时间戳, "格式")}}。Here the 'timestamp' is usually a 10-digit Unix timestamp, and the 'format' follows the special time formatting conventions of Golang (Go language), for example,"2006-01-02"Represents year-month-date,"15:04:05"Represents hours-minutes-seconds,
From an essential point of view,stampToDateIt is a puredata formatting toolEnglish, rather than data acquisition tool.It receives an existing timestamp (usually the content creation or update time read from the database) and then converts it into a human-readable date or time string according to the format specified by the developer.stampToDateIt does not care where the timestamp is obtained from, it is only responsible for converting according to the established rules.
In a multi-site environmentstampToDateSpecial considerations
SincestampToDateIf it does not involve the selection of data sources, does it not have any special considerations in a multi-site environment?Not so.Data sourceandDisplay strategyConsiderations on it.
1. Data source clarity
In the multi-site architecture of AnQiCMS, the data of each site is relatively independent. When we use for examplearchiveList/categoryList/archiveDetailTags obtained when filtering articles or categories typically contain an optionalsiteIdparameter. The purpose of this parameter is to allow you to use a template in a site,Call data from another site.
For example, you might want to display the latest articles from all child sites in a master site template. At this point, you would iterate over differentsiteIdto callarchiveList. Once the 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障碍.stampToDateto format:{{stampToDate(archive.CreatedTime, "2006-01-02 15:04")}}.
The core lies inThe 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. English of cross-site time format localization and consistency
这才是stampToDateIn a multi-site environment, it truly requires "special attention". AlthoughstampToDateProvided flexible formatting capabilities, but itselfDoes not have localization (Localization) capabilities. That is to say, it will not automatically adjust the output date format according to the language or regional settings of the current site.
假设你管理了两个站点:一个面向中国用户(语言:English),另一个面向欧洲用户(语言:English)。
- In the Chinese site, you may want the date format to be "2023 January 15".
- In the English site, you may want the date format to be “15 January 2023” or “15/01/2023”.
If you simply use the template on both sites{{stampToDate(item.CreatedTime, "2006-01-02")}}, then both sites will output a unified format such as "2023-01-15".This may be acceptable for some scenarios, but for websites that pursue user experience and localized content, such a unified format may not conform to the reading habits of users.
To solve this problem, as a website operator or template developer, you need to adoptactive strategies:
- Template customization:The most direct way is to create or modify the corresponding template file for each different language or regional site, and manually set different Golang date format strings. For example, in the Chinese template, it uses
"2006年01月02日"English template usage"02 January 2006". - Using system configuration:AnQiCMS provides
systemTag to get background configuration information, you can define a special date format string parameter for each site in the "Global Function Settings" or "Custom Parameter Settings" in the background (for example,"DateFormat_Zh"/"DateFormat_En")。Then, in the template, obtain this format string and pass it to{% system with name="DateFormat_Zh" %}获取到这个格式字符串,再将其传递给stampToDate.Thus, when the site switches, the template will dynamically adjust 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 short,stampToDateThe label itself does not have any new parameters or behavior changes in the multi-site environment of AnQiCMS. Its "special considerations" mainly include: ensuring you obtain the timestamp from the correct data source, as well as adapting to the localization needs of different sites.Automatically design and apply the corresponding date format stringThis requires operators and developers to plan the display of date and time in detail during template design and content management to provide a** user experience.
Common Questions (FAQ)
Q1:stampToDateIs the tag necessary?siteIdParameter to specify from which site to get the timestamp?
A1:Not required.stampToDateLabel 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 needsiteIdParameter. The timestamp is usually obtained by retrieving tags (such asarchiveList/archiveDetail) from data objects of specific sites.
Q2: If my AnQiCMS has deployed multiple language sites,stampToDateWill the tags automatically output the corresponding date format according to the site language?
A2:Will not automatically.stampToDateThe label does not have the function of automatic localization of date formats.It simply converts the Golang format string you provide.systemLabel configuration of different date format strings.
Q3: Can I set a global date format in the AnQiCMS backend and then 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.{% 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.