How to quickly view the original data output by the `archiveFilters` tag during template debugging?

Calendar 👁️ 67

As an experienced website operations expert, I know that quickly and effectively debugging template tags during the development and maintenance of AnQiCMS (AnQiCMS) templates is the key to improving efficiency. Especially when we need to handle things likearchiveFiltersWhen returning tags for complex data structures, it is particularly important to quickly perceive the original data inside.This is not just to verify whether the label output is correct, but also to quickly locate and solve problems when encountering them.

archiveFiltersThe tag is a very powerful feature in AnQi CMS, which allows us to build dynamic filtering conditions based on various parameters of the document (for example, filtering by 'house type' or 'house size' on a real estate website). It is usually associated witharchiveListTags can be combined to provide flexible content filtering options on document lists or category pages.

However,archiveFiltersThe output of the tag is not a simple string or number, it returns a complex data collection of nested arrays (or called slices) and objects (or called structures). Specifically, it will return afiltersA variable, this variable itself is an array of objects containing multiple filter groups. Each filter group also containsName(parameter name),FieldName(parameter field name) and aItemsarray. AndItemsIn the array, each element is an object that containsLabel(Filter value),Link(Filter value link) andIsCurrent(Selected) object.

Because of this multi-layered complexity, when we try to use it directly in the template{{ filters }}When printing its content, it often only gets a brief, unreadable representation, making it difficult to obtain the actual original data structure and values.At this point, we need some special debugging techniques to 'penetrate' its internal.

Core debugging技巧:Quick CheckarchiveFiltersLabel original data

There are several effective methods that can help us quickly view in the AnQi CMS template debuggingarchiveFiltersLabel outputs the original data. These methods take advantage of the underlying Go language template engine of AnQi CMS, allowing direct exposure of the data structure.

Method one: utilizedumpFilter

dumpThe filter is a very practical debugging tool provided by the Anqi CMS template engine.Its function is to "print the structure type and value of the variable", which is what we need to view the original data of complex variables.

When you need to debug in the templatearchiveFiltersjust add it after the output variable of the tag|dumpfor example:

{# 假设你在 archiveFilters 标签中定义了变量名为 filters #}
<pre>
  {{ filters|dump }}
</pre>

Hint:I am used to putting this debug code in<pre>Tag inside.preThe tag retains the text format, which is very helpful for viewing complex structured data output, and can avoid the default HTML rendering of the browser affecting its layout.

Temporarily add this code to your template file (for examplecategory/list.htmlorindex.htmldepending on where you usedarchiveFiltersthe tag) and then refresh the page. You will see it on the pagefiltersA complete Go language struct representation of a variable, including the names, types, and current values of each field. This is like directly printing the data structure from the Go code, which can clearly displayarchiveFiltersWhat data was output, and what is the specific format of this data.

Method two: usestringformatFilter pairing%#v

exceptdumpFilter,stringformatFilter pairing%#vFormatting parameters can also achieve a similar effect.stringformatThe filter can convert variables to strings according to the specified Go language formatting rules, while%#vIt is used to output the source code snippet representation of Go structures.

The usage is as follows:

{# 同样,将这段代码临时添加到模板中 #}
<pre>
  {{ filters|stringformat:"%#v" }}
</pre>

The effect of this code is similar to|dumpThe filter is very similar, it will also outputfiltersThe Go struct representation of a variable. You can choose to use any of them according to your personal preference. They can all help you obtain it quicklyarchiveFiltersLabel the original output data to better understand the data structure and correctly reference and process these data in the template.

Deeply understand data structure: Iterative output

Althoughdumporstringformat:"%#v"Can provide an overview of the original data, but sometimes we may need more humanized, more readable output, or want to verify the value of specific fields. At this time, it is necessary to combineforloop andifDetermine layer-by-layer iterative outputarchiveFiltersThis method is not as good as doing it directly.dumpSo "quick and original", but it can help us understand the data flow more deeply and display the data in the format we expect.

Below is an iteration output in the template.archiveFiltersDetailed data example:

{# 首先,定义 archiveFilters 标签,这里假设moduleId为1,allText为“全部” #}
{% archiveFilters filters with moduleId="1" allText="全部" %}
  <h3>`archiveFilters` 原始数据(迭代输出):</h3>
  {% for item in filters %}
    <div style="border: 1px solid #ccc; margin-bottom: 10px; padding: 10px;">
      <p><strong>参数名称 (Name):</strong> {{ item.Name }}</p>
      <p><strong>参数字段名 (FieldName):</strong> {{ item.FieldName }}</p>
      <p><strong>可选值 (Items):</strong></p>
      <ul>
        {% for val in item.Items %}
          <li style="margin-left: 20px;">
            <a href="{{ val.Link }}" {% if val.IsCurrent %}class="active-filter"{% endif %}>
              {{ val.Label }}
            </a>
            {% if val.IsCurrent %} (当前选中){% endif %}
            (链接: {{ val.Link }})
          </li>
        {% endfor %}
      </ul>
    </div>
  {% empty %}
    <p>没有找到任何筛选参数。</p>
  {% endfor %}
{% endarchiveFilters %}

Through this iteration output example, we can not only see the names and field names of each filter group, but also clearly see the labels, corresponding links, and whether they are currently selected.This approach is very helpful for understanding the actual application logic of data in front-end templates.

Points to note in debugging practice

Whether using in template debugging process,dumpFilters or iterative output, the following points need to be noted:

  1. The principle of temporality:Debug code should only be used during development and testing phases. Once the issue is resolved, it must be removed from the production environment template.Exposing internal data structures may pose security risks, and unprocessed debugging information may also affect user experience and page loading speed.
  2. View the page source:Browsers typically parse and render HTML. Fordumporstringformat:"%#v"The original data, if you see the format is messy or incomplete in your browser, please try to view the page source code (usually throughCtrl+UOr right-click the menu and select "View Page Source"), where it will display the original HTML response uninterpreted by the browser, including your debugging output.
  3. safeFilter:AlthoughdumpandstringformatIt usually outputs plain text, but in some cases, if the variable itself contains HTML special characters, and you want them to be displayed in their original form rather than being escaped by the browser (for example<displayed as&lt;It may be necessary to add debugging output for|safea filter. For example:{{ filters|dump|safe }}.

Summary

Mastering these template debugging techniques can greatly improve your efficiency in Anqi CMS development.archiveFiltersTags are an important tool for handling complex filtering logic, and an accurate understanding of their internal data is the foundation for building user-friendly website interfaces. Bydumporstringformat:"%#v"Quickly view the original data, combine iterative output to deeply understand the data structure, and you will be able to confidently master the template development of Anqi CMS.


Frequently Asked Questions (FAQ)

1. Why do I use it directly in the template?{{ filters }}Cannot seearchiveFiltersDetailed data of the tag?

{{ filters }}This syntax is used in the template to output simple variables (such as strings, numbers). ButarchiveFiltersThe tag returns a complex nested data structure, containing multiple levels of arrays and objects.When output directly, the template engine usually only converts it into a brief string representation and does not display each field and value in detail.|dumpor|stringformat:"%#v"This kind of filter.

Do these debugging codes affect website performance or SEO?

Will do. Debugging code usually prints a large amount of internal data, which increases the size of the page's HTML file, thus making it light

Related articles

`archiveFilters` tag supports dropdown menu or checkbox form of filtering interface?

AnQiCMS provides a highly flexible solution in content management and display, especially in handling dynamic content filtering, where its `archiveFilters` tag plays a core role.Does the `archiveFilters` tag support a dropdown menu or checkbox form of the filter interface?This question can be understood as: The `archiveFilters` tag itself does not directly generate visible UI elements, such as dropdown menus or checkboxes

2025-11-06

How will the `archiveFilters` tag handle if the document does not have a value for a certain filter parameter?

As an experienced website operations expert, I often deal with content management systems in my daily work and understand the importance of flexible use of template tags for website performance and user experience.AnQiCMS (AnQiCMS) with its powerful features and high performance brought by the Go language has become the preferred choice for many enterprises and operation teams.Today, let's delve into a detail issue that may be encountered in template development and content operation: **What will happen when a filter parameter dependent on the `archiveFilters` tag does not have a corresponding value?

2025-11-06

How to use CSS/JavaScript to beautify the `archiveFilters` tag generated filter interface to enhance user experience?

As an experienced website operations expert, I am well aware of the importance of user experience for the success of a website, especially in complex filtering functions.The `archiveFilters` tag provided by AnQiCMS greatly facilitates the rapid construction of the document parameter filtering interface.However, relying solely on default styles often fails to meet the high requirements of modern websites for aesthetics and interactivity.

2025-11-06

What are the specific application scenarios of the `IsCurrent` field in the `archiveFilters` tag in front-end development?

Good, as an experienced website operations expert, I am very willing to delve into the specific application scenarios of the `archiveFilters` tag's `IsCurrent` field in front-end development in AnQi CMS.We will integrate technical details into practical applications in a natural and fluent manner, hoping to bring you some practical inspiration.--- ## Deep Analysis of Anqi CMS Front-end Development: The Magic of `IsCurrent` Field in `archiveFilters` Tag In the Anqi CMS ecosystem

2025-11-06

`archiveFilters` label can integrate third-party traffic statistics tools to track the usage of the filtering function?

As an experienced website operations expert, I know that every user interaction detail contains the potential to enhance the value of the website.AnQiCMS (AnQiCMS) provides us with a wide range of space to implement our operational strategies with its powerful content management capabilities and flexible template system.Today, let's delve into a frequently discussed issue in精细化运营: Can the `archiveFilters` tag integrate third-party traffic statistics tools to track the usage of the filtering function?

2025-11-06

How to ensure that the `archiveFilters` tag-generated filter links do not lead to duplicate page content being penalized by search engines?

As an experienced website operations expert, I am fully aware that while using the powerful functions of a content management system (CMS) to bring convenience to the website, we must also be vigilant about the SEO risks that may come with it.AnQiCMS (AnQiCMS) with its flexible content model and powerful template tags, provides us with great freedom in content display, among which the `archiveFilters` tag is one of its highlights, helping users easily build complex filtering functions, greatly enhancing the user experience.

2025-11-06

How can the `archiveFilters` tag help analyze user preferences and optimize content strategy in content operations?

As an experienced website operations expert, I know that how to accurately capture user needs and adjust content strategies accordingly is the key to whether a website can stand out in the vast ocean of Internet information.AnQiCMS (AnQiCMS) with its flexible and powerful functions, provides many tools for content operators, among which the `archiveFilters` tag is a key to understanding user preferences and optimizing content strategies.### `archiveFilters` label: The first window to understand user needs Today, digital marketing is becoming more and more refined

2025-11-06

Does the `archiveFilters` tag support setting the default value for filter conditions?

As an experienced website operations expert, I know that how to flexibly use various tags to meet complex business needs is crucial in a powerful content management system like AnQiCMS.Today, let's delve deeply into a common question about the `archiveFilters` tag: Does the `archiveFilters` tag support setting default values for filter conditions?Can AnQiCMS `archiveFilters` tag set the default value of the filter conditions?

2025-11-06