How to print the original input timestamp value of `stampToDate` when debugging the AnQi CMS template?

Calendar 👁️ 67

As an experienced website operations expert, I am well aware that AnQiCMS (AnQiCMS) brings great convenience to small and medium-sized enterprises and content operation teams with its efficient Go language architecture and rich features.System design focuses on practicality and scalability, especially in template customization and content presentation, which provides us with great freedom.In daily content operation and maintenance, template debugging is an indispensable part, and correctly obtaining and understanding the original data of variables in the template is crucial for efficient troubleshooting.

Today, we will delve into a very practical skill in the debugging of AnQi CMS templates: how to handle timestamps (Unix timestamp), especially when we need to usestampToDateHow to elegantly view the original input timestamp value of this powerful formatting tag.

UnderstandingstampToDateThe role of tags.

In AnQi CMS template system, we often encounter the need to convert the timestamp stored in the database (usually a 10-digit or 13-digit Unix timestamp) into a user-friendly date and time format. At this time,stampToDateThe label comes in handy. As described in its documentation, its basic usage is{{stampToDate(时间戳, "格式")}}For example, you may see such code on the document details page, used to display the publication time of the article:

<span>发布时间:{{stampToDate(archive.CreatedTime, "2006年01月02日 15:04")}}</span>

Herearchive.CreatedTimeIt is a timestamp value, while"2006年01月02日 15:04"is a Go language style formatted string, which tells the system how to render the timestamp into the date and time text we expect.stampToDateThe strength lies in its simplification of the time formatting process, but sometimes we don't want to see the formatted result, but rather want to explore and see what the original timestamp is.

Why do you need to view the original timestamp?

View during template debugging, checkstampToDateThe original input timestamp value has many practical meanings:

first, Data ValidationWhen the time displayed on the page is incorrect, or when the default value such as "1970-01-01" appears, the original timestamp can help us quickly determine whether the problem lies in the timestamp itself (such as a value of 0, negative, or an illegal format), or instampToDateThe formatting parameters on.

secondly,Integrated or compared with other systems.. When managing multiple sites or performing data migration, we sometimes need to ensure that the timestamp within the Anqin CMS is consistent with the timestamp of the external system.Directly viewing the original value can provide accurate reference.

Moreover,Understanding data types.. AlthoughstampToDateThe tag intelligently handles timestamps, but the underlying variables (such as)archive.CreatedTime) may be a Go language'stime.TimeA structure may also be a pure integer type. Viewing its original value and type helps us understand the data model more deeply, laying the groundwork for subsequent secondary development or complex logic processing.

Unveiling the debugging tool:dumpFilter

The template system of Anqi CMS provides developers with a rich set of filters, one of which is an extremely useful 'secret weapon' for debugging.dumpA filter. As the name suggests,dumpCan 'dump' the complete structure, type, and current value of a variable, as if it were an X-ray machine, revealing the inner workings of the variable.

dumpThe usage of the filter is extremely concise, you just need to add it after any variable you want to check|dumpThat's it, for example:{{ 变量名称|dump }}.

When you are going todumpThe filter is applied tostampToDateWhen the original input variable is processed, it outputs the underlying Go language structure, which includes the original Unix timestamp value we want to see.

Practice exercise: Print in the templateCreatedTimeoriginal timestamp

Let's take a common scenario as an example: You are debugging an article detail page and need to viewarchive.CreatedTimeoriginal timestamp.

Generally, you will see the following code to display the formatted time:

{# 假设这是您的文章详情模板文件中的一部分,例如`archive/detail.html` #}
<p>
    文章标题:{{ archive.Title }} <br>
    发布时间(格式化):{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04:05") }}
</p>

To viewarchive.CreatedTimeThe original timestamp value, you just need to find it in the templatearchive.CreatedTimeisstampToDateHandle the position before, or insert a line of debug code like this:

{# 调试代码:插入在您需要检查的变量旁边 #}
<p>
    文章标题:{{ archive.Title }} <br>
    发布时间(格式化):{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04:05") }} <br>
    原始CreatedTime数据(调试用):{{ archive.CreatedTime|dump }}
</p>

Save the template file and refresh the browser after that, you will find that the page not only displays the normal article title and formatted publishing time, but also an additional line of output for the "original CreatedTime data". This line of output is likely to look like a Go languagetime.TimeStructure, for example:

&time.Time{wall:0x...000000, ext:63799651200, loc:(*time.Location)(0x...)}

HereextThe field (or similar-named internal field) typically contains the original Unix timestamp (in seconds or nanoseconds, depending on the system implementation), and you can use this value for verification or further processing.

Experience has taught me that it is a good habit to wrap debug output in HTML comments, so that you can see the information without affecting the normal layout and style of the page:

{# 将调试信息放入HTML注释,方便查看源代码 #}
<!-- 原始CreatedTime数据(调试用):{{ archive.CreatedTime|dump }} -->
<p>
    文章标题:{{ archive.Title }} <br>
    发布时间(格式化):{{ stampToDate(archive.CreatedTime, "2006-01-02 15:04:05") }}
</p>

This way, you just need to view the page source code (usually through the "Inspect" or "View Page Source" feature in the browser context menu), and you can find this debugging information, while the page itself still looks neat.

Template debugging practices

MasterdumpFilters are just the first step, and in the template debugging of AnQi CMS, we also have some universally applicable practices:

  1. Immediate cleanup: Debug code should only be added when necessary, and must be removed immediately from the template once the problem is solved.Retaining too much debug information not only increases the size of the page but may also expose sensitive data.
  2. Precise locationAvoid adding blindly at uncertain positions|dumpFirstly, judge roughly which area or which variable may be problematic based on the page performance, and then insert debugging code specifically.
  3. Combine browser developer tools:dumpThe filter outputs server-side rendered HTML content, combined with the browser developer tools (F12), it is more convenient to view elements, network requests, and JavaScript errors, forming a complete debugging workflow.
  4. Understand the template contextInforLoop orifWhen debugging variables in conditional blocks, make sure you are using the correct context with `|dump

Related articles

How to use `stampToDate` to format a timestamp into a time format that includes AM/PM indicators?

As an experienced website operations expert, I am well aware that the way website content is presented is crucial for user experience and the efficiency of information transmission.Especially when dealing with basic information such as time, if it can be formatted in a way that is accustomed to the user (for example, including the 12-hour AM/PM format), it will greatly enhance the professionalism and user-friendliness of the website.AnQiCMS (AnQiCMS) is a powerful and detail-oriented content management system that naturally also provides flexible time formatting tools. Today

2025-11-07

`CreatedTime` as a 10-digit timestamp, do you need to multiply it by 1000 before using `stampToDate`?

The mystery of timestamp conversion in AnQi CMS: As an experienced website operator and deep user of AnQi CMS, I know how common and crucial the handling of time data is in daily content management and template development.Especially when using a high-efficiency system like the Anqi CMS built with Go language, understanding and correct use of template tags are particularly important. Recently

2025-11-07

In the AnQi CMS template, can the `stampToDate` function display relative time such as 'X days ago' or 'X hours ago'?

As an experienced website operations expert, I know that flexible time display in content management systems is crucial for improving user experience and content timeliness.Especially displays such relative time as "X days ago", "X hours ago", which allows readers to understand the age of the content at a glance, thus better deciding whether to delve deeper into reading.Today, let's delve into whether the `stampToDate` tag built into the Anqi CMS template can achieve this relative time display, and how we should go about implementing it.--- ## AnQi CMS template in

2025-11-07

How to concatenate the formatted date of the `stampToDate` tag with other text content to form a complete display message?

As an experienced website operation expert, I fully understand that how to flexibly display information is crucial for improving user experience and meeting operation requirements.AnQiCMS (AnQiCMS) is an efficient and easy-to-use content management system that provides powerful template tag functions, among which the `stampToDate` tag is a tool to process timestamps and format them into readable date strings.

2025-11-07

Does the `stampToDate` tag have different formatting capabilities between different versions of Anqi CMS?

As an experienced website operations expert, I am deeply familiar with the various functions and content operation strategies of AnQi CMS, and I am happy to analyze the time formatting capability of the `stampToDate` tag across different versions of AnQi CMS.This tag plays an important role in daily content display, especially for websites that need to finely control the display format of time, where stability and functional characteristics are of great concern to operators.### AnQi CMS `stampToDate` tag time formatting capability

2025-11-07

How to ensure that `stampToDate` outputs a consistent date format on different server operating systems (such as Linux/Windows)?

In website operation, the display of content publishing time is often one of the details that users pay attention to. Ensuring that these dates and times are presented in a consistent format across different server environments (such as the familiar Linux and Windows) is an important factor in improving user experience and maintaining website professionalism.As an experienced operator of AnQi CMS, I am well aware of its powerful capabilities based on the Go language, especially the unique advantages of the template tag `stampToDate` in dealing with such issues.Today, let's delve deeper

2025-11-07

In the `tag-stampToDate.md` example, how is the `publishStamp` variable defined, and can it be used in practice?

As an experienced website operations expert, I am well aware of the importance of content timeliness and display methods for user experience and SEO optimization in my daily work.AnQiCMS (AnQiCMS) provides great convenience for us with its flexible template engine and rich tag system.TodayReveal

2025-11-07

How to batch update the date format string of all `stampToDate` tags in the Anqi CMS template?

How to efficiently batch update the date format string of the `stampToDate` tag in AnQi CMS template?Practical Guide As an experienced website operations expert, I am well aware of the importance of the timeliness and presentation of website content for user experience and brand image.In such an efficient and flexible system as Anqi CMS, we often use `stampToDate` such date formatting labels to display the content publication or update time.

2025-11-07