How to debug template display issues in AnQi CMS, such as using the `dump` filter to print variables?

Calendar 👁️ 61

Smart debugging of Anqi CMS templates: how to usedumpThe filter easily locates display issues

When using AnQi CMS to build a website, we sometimes encounter situations where template content is not displayed as expected.For example, you expect the article title to be displayed at a certain position, but instead, it is blank;Or the list data is incomplete, the content of some custom field is always unable to be presented correctly.These questions are often confusing because the data is set in the background, but it is not known why the front-end does not display.

If you can "see through" the real content of the variables in the template, it will undoubtedly greatly improve the efficiency of solving such problems. Fortunately, AnQi CMS provides a very practical built-in tool -dumpA filter that acts like a 'perspective mirror', helping us clearly see the type, structure, and actual value of any variables in the template.

Get to know your debugging tool:dumpFilter

dumpThe main function of the filter is to output all the information of the variable, including its data type, internal structure, and current stored value, in a detailed text form to the page.This is crucial for understanding the data received by the template engine and determining whether it is a spelling error in the variable name, the data is empty, or the data type does not match.

Its usage is very simple, you just need to add it after any variable you want to check|dumpLike this:

{{ 你的变量名|dump }}

Insert this line of code directly into your.htmlIn the template file, after saving and refreshing the page, you will be able to see the detailed information of this variable in the browser.

Actual application: in different scenarios.dumpUsage

In order to understand betterdumpThe power, let's take a look at several common application scenarios:

1. Check the value and structure of a single variable

Suppose you are on the article detail page (usuallytemplate/default/article/detail.htmlIn the details page of another model, it is expected to display the article title{{ archive.Title }}But the page is blank. You can try this in the template:

<h1>{{ archive.Title|dump }}</h1>

After refreshing the page, ifarchive.Titleis empty,dumpIt may display something similarstring(0) ""such characters indicate that it is an empty string. If it shows the correct title text, but your<h1>The label style is wrong, then you know the problem is not in the data itself, but in CSS.

To go further, if you want to view the entirearchiveobject's detailed information, you can do this:

{{ archive|dump }}

This will outputarchiveThe complete Go language struct information of a variable, for example&config.Archive{Id:1, Title:"我的第一篇文章", Description:"...", CreatedTime:1678886400, ...}. Through this output, you can clearly seearchiveAn object includes which fields and the current value of each field. This can help you quickly find out if there are any spelling mistakes (such as writing it asTitlee), or the field you are expecting (such asDescriptionIt is actually empty.

2. Check list items in the loop.

When you use on the article list page{% archiveList archives with type="page" %}While traversing the article, if you find a list item(item) is displaying an error, you can apply thedumpfilter to the loop inside.itemUp:

{% archiveList archives with type="page" limit="10" %}
    {% for item in archives %}
        <li>
            {{ item|dump }}
            {# 或者只检查你怀疑有问题的字段 #}
            <h5>{{ item.Title|dump }}</h5>
        </li>
    {% endfor %}
{% endarchiveList %}

This page will display each one by oneitem(or its specific field) in detail. You can see if allitemhave problems, or only someitemdata does not meet expectations. The output may be similar&config.Archive{Id:2, Title:"另一个标题", ...}Help you confirm that each list item's data is correct.

3. View global or complex objects

Sometimes, you may need to view a large dataset in the page context, such as a category listcategoriesOr some custom global configuration object. You can use it directly in any position of the template (usually at the top of the page or near the area where you want to debug)dump:

{{ categories|dump }}
{{ system|dump }} {# 检查系统配置变量 #}

This will output the entirecategoriesarray orsystemThe detailed structure and content of an object. For multi-layered nested data,dumpinformation of each layer is recursively displayed, which is very helpful for understanding the complex data flow.

Interpretdumpoutput information

When you see something similar&config.Archive{Id:1, Title:"...", CreatedTime:1678886400, ...}This is actually the representation of a struct in Go language.

  • &config.ArchiveThis means you are looking at a pointer toconfigUnder packageArchivePointer to the structure.ArchiveIt is the way that AnQi CMS defines the article data model.
  • Id:1: It indicates that the ID field value of this object is 1.
  • Title:"我的第一篇文章": It indicates that the value of the title field is 'My First Article'.
  • CreatedTime:1678886400: Indicates that the creation time is a Unix timestamp. If you expect a formatted date, you know that you need to usestampToDateFilter it to process it.

With this information, you can:

  • Confirm if the variable exists:IfdumpThe output is:nilOr blank, indicating that the variable is either undefined or a null value.
  • Check variable type:Understand whether it is a string, number, boolean, array, or structure, as this helps you choose the correct template tag or filter to process it.
  • Verify variable content:Check if the specific value is consistent with what you expected.
  • Spelling error found: IfdumpThe output does not match the expected, or only part of the fields is displayed, it is likely that the field name you accessed is incorrect.

Debugging process suggestion

NowdumpFilter, you can follow a simple debugging process:

  1. Identify the area of the problem:Determine which part of the content on the page is displayed incorrectly

Related articles

What basic conventions should the template files of Anqi CMS follow to correctly display the content structure?

In Anqi CMS, template files are the basis for presenting website content.It is not just a simple HTML file, but a set of blueprints that follow specific conventions and rules. Only by accurately adhering to these conventions can the system correctly parse, render, and display the structure of your website content.Understanding these basic conventions can help you customize and manage your website more efficiently, ensuring that content is presented in the way you expect to visitors.### The storage location and basic format of the template file Firstly, Anqi CMS has clear requirements for the storage location of template files

2025-11-09

How to correctly display and load images on the front-end page after the website enables Webp image format?

In website operation, the speed of image loading is crucial for user experience and Search Engine Optimization (SEO).WebP is a modern image format that, with its excellent compression performance, significantly reduces file size while maintaining image quality, thus greatly enhancing website loading speed.AnQiCMS (AnQiCMS) fully understands this and has built-in support for WebP image format in its system, making it easy for users to turn it on and benefit from it.However, after enabling the WebP feature, many users may be confused: how can the front-end page correctly display and load these WebP images

2025-11-09

How does Anqi CMS handle and display external links in content, such as adding the `rel="nofollow"` attribute?

In website operation, the management of external links is an indispensable part of content strategy and search engine optimization (SEO).Especially properties like `rel="nofollow"`, which tell search engines not to pass link weight to the linked page, are crucial for managing the link health of a website and avoiding potential SEO risks.AnQiCMS (AnQiCMS) provides multiple ways to handle and display external links in content, including automatically adding the `rel="nofollow"` attribute

2025-11-09

How to call the backend custom Json-LD structured data in AnQi CMS template and display it?

Today with the rich content on websites, how to make search engines accurately understand web content and display it in a more user-friendly manner has become a key link in website operation.Structured data (usually in Json-LD format) is an important tool to achieve this goal.By embedding Json-LD code in the page, we can provide standardized information for search engines about various content such as articles, products, and reviews, thereby having the opportunity to obtain richer search result displays, which is what we commonly refer to as 'rich snippets' or 'rich results'

2025-11-09

How to display the navigation list configured in AnQi CMS and support multi-level dropdown menus?

The website navigation acts as a 'compass' for users visiting the website, and its clarity and ease of use directly affect user experience and the efficiency of information acquisition.For a corporate website, a well-structured navigation system that supports multi-level dropdowns is essential.AnQiCMS (AnQiCMS) understands this and provides an intuitive and powerful backend configuration function, allowing you to easily build a navigation menu with a sense of hierarchy.Next, we will explore how to configure the navigation list in the Anqi CMS backend and make it perfectly present multi-level dropdown effects on the front end.--- ### Step 1

2025-11-09

How to use the `lorem` tag to generate placeholder text in the early stages of development, and quickly preview the display effect of the template?

At the early stage of website template development, designers and developers often face a common challenge: how to effectively preview and adjust the layout, style, and responsive performance of the template without real content?If each modification requires manual input of a large amount of text to test the effect, it will undoubtedly greatly reduce development efficiency.AnQi CMS knows this pain point and provides a very convenient and efficient built-in tag called `lorem`, which can help us quickly generate placeholder text during the development stage, so that we can focus on the visual presentation of the template itself.### `lorem`

2025-11-09

How to display user group (VIP system) information in AnQiCMS to support member level display?

In today's internet world, the member system of websites and user grouping functions have become increasingly common. It not only helps operators provide differentiated services, but also is an important means to realize content monetization and enhance user stickiness.AnQi CMS knows this, therefore it has built a powerful user group management and VIP system, allowing the website to flexibly provide customized content and permissions for different user groups.How can we clearly display user group information (that is, VIP level) on the front-end page of a website built with Anqi CMS?This is actually more direct than imagined

2025-11-09

How to customize the display layout of the article detail page in AnQiCMS?

In website operation, the article detail page is not just a carrier of content, but also a key link for brand image, user experience, and SEO effect.A well-designed and logically organized detail page that can effectively increase user reading time, reduce bounce rate, and help search engines better understand and crawl content.For friends using AnQiCMS, deeply customizing the display layout of the article detail page is actually more flexible and convenient than you imagine.AnQiCMS as an efficient content management system, deeply understands the needs of content operators

2025-11-09