How to use the `add` filter to dynamically generate the complete path segment in the breadcrumb navigation (`breadcrumb`)?

Calendar 👁️ 68

In website operation, breadcrumb navigation is one of the key elements to improve user experience and website SEO performance.It clearly shows the user's position on the website and provides a convenient way to return to the previous level page.AnQi CMS provides a powerful and flexible template tag system, wherebreadcrumbTags can help us easily implement breadcrumb navigation. But if we need to dynamically adjust the path text or links in the breadcrumb navigation, the Anqi CMS'saddThe filter can play its unique role.

breadcrumbThe tag can intelligently generate the navigation path of the current page. It usually outputs a list containing multiple navigation items, each of which hasName(display name) andLink(Link address) two basic attributes. For example, a basic breadcrumb navigation code might look like this:

{% breadcrumb crumbs with index="首页" %}
<nav class="breadcrumb">
    <ol>
        {% for item in crumbs %}
            <li>
                {% if forloop.Last %}
                    <span>{{ item.Name }}</span>
                {% else %}
                    <a href="{{ item.Link }}">{{ item.Name }}</a>
                {% endif %}
            </li>
        {% endfor %}
    </ol>
</nav>
{% endbreadcrumb %}

This code will render a navigation path starting with 'Home' and ending at the current page.

AndaddA filter, as the name implies, is mainly used to add numbers or concatenate strings. Its usage is very intuitive, usually{{ 变量 | add:附加值 }}. When processing strings, it appends additional values to the content of the variable. It is this feature that makesaddfilters particularly useful when dynamically building breadcrumb path segments.

Flexible application in breadcrumb navigationaddFilter

Imagine that we may need to dynamically add additional information to a certain part of the breadcrumb navigation or modify its link based on a specific scenario.addThe filter can be used here.

Dynamically customize the "home" text of the breadcrumb.

breadcrumbTags support throughindexParameters to set the starting text of the breadcrumb navigation, usually "Home" or "Home". If we want to personalize the text more, for example, to display as "My website > Home", we can combineaddTo implement a filter:

{% breadcrumb crumbs with index="我的网站"|add:" > 首页" %}
<nav class="breadcrumb">
    <ol>
        {% for item in crumbs %}
            <li>
                {% if forloop.Last %}
                    <span>{{ item.Name }}</span>
                {% else %}
                    <a href="{{ item.Link }}">{{ item.Name }}</a>
                {% endif %}
            </li>
        {% endfor %}
    </ol>
</nav>
{% endbreadcrumb %}

In this way, the first navigation item of the breadcrumb will dynamically display as "My website > Home", without writing the entire string in the template.

Add dynamic tracking parameters to breadcrumb links

In website operation, we often need to track the source of user clicks to analyze traffic and optimize user paths. For example, we can dynamically add a UTM tracking parameter to all links in the breadcrumb navigation to identify where the clicks come from:

{% breadcrumb crumbs with index="首页" %}
<nav class="breadcrumb">
    <ol>
        {% for item in crumbs %}
            <li>
                {% if forloop.Last %}
                    <span>{{ item.Name }}</span>
                {% else %}
                    {# 为每个非当前页面的链接添加追踪参数 #}
                    <a href="{{ item.Link|add:"?utm_source=breadcrumb&utm_medium=nav" }}">{{ item.Name }}</a>
                {% endif %}
            </li>
        {% endfor %}
    </ol>
</nav>
{% endbreadcrumb %}

By{{ item.Link|add:"?utm_source=breadcrumb&utm_medium=nav" }}We successfully appended tracking parameters to each breadcrumb link dynamically without affecting the original link.This provides great convenience for data analysis without modifying the underlying URL structure.

Dynamically adjust the breadcrumb display name to provide additional information

Sometimes, we may want to include some contextual information in the display name of the breadcrumb navigation. For example, on the article detail page, add a suffix to the last item of the breadcrumbs (i.e., the current article title) to indicate that this is the 'current article':

{% breadcrumb crumbs with index="首页" %}
<nav class="breadcrumb">
    <ol>
        {% for item in crumbs %}
            <li>
                {% if forloop.Last %}
                    {# 为当前页面的名称添加“(当前)”后缀 #}
                    <span>{{ item.Name|add:" (当前)" }}</span>
                {% else %}
                    <a href="{{ item.Link }}">{{ item.Name }}</a>
                {% endif %}
            </li>
        {% endfor %}
    </ol>
</nav>
{% endbreadcrumb %}

This will clearly tell the user which page they are browsing.

Useful tips and precautions

  • Combined with logical labels:addFilters are usually used withif/forloop.LastUse logical tags in combination to achieve more fine-grained dynamic control. For example, add link parameters only for non-current pages, or add special text only for the current page.
  • Pay attention to URL encoding.When the concatenated string contains special characters, such as those in URL parameters, such as&It usually does not require additional manual encoding because the Anqi CMS template engine handles most of the URL validity. However, in certain cases, if the content to be concatenated itself needs URL encoding, consider usingurlencodefilter preprocessing.
  • SEO impact: For links that add tracking parameters, modern search engines typically recognize and ignore these parameters, and do not consider them as duplicate content.But excessive or inappropriate link modifications may still pose SEO risks, and it is recommended to operate cautiously and conduct tests.
  • readability: AlthoughaddThe filter function is powerful, but overly complex concatenation logic can reduce the readability of the template. It is considered to preprocess the data at the controller layer when necessary, and then pass it to the template.

In summary, of Anqi CMS'saddThe filter provides a simple and effective means for us to implement dynamic content in breadcrumb navigation.Whether it is adjusting the display text or modifying the link, it can help website operators more flexibly control page elements, thus optimizing the user experience and data analysis effect.


Frequently Asked Questions (FAQ)

1.addCan the filter only be used for string concatenation?

Not at all.addThe filter can not only be used for string concatenation, but also for numeric addition operations. For example,{{ 5|add:2 }}will output7When adding a string with a mixed number, if the number can be converted to a string, it will try to concatenate the strings.If the conversion fails, it may only output the original string or ignore the parts that cannot be processed.

2. Used in breadcrumb linksaddWill adding parameters to the filter have a negative impact on the website's SEO?

Generally speaking, adding tracking parameters (such as?utm_source=...The negative impact on SEO is very small, even negligible.Mainstream search engines usually recognize and ignore tracking parameters in URLs to avoid treating them as different pages and causing duplicate content issues.However, if the parameters added change the actual content of the page or lead to a large number of different URLs pointing to the same content, it may be necessary to perform additional SEO processing, such as usingrel="canonical"tags to specify standard URLs.

3. BesidesaddFilter, what are some filters in Anq CMS that can be used for dynamic string processing?

AnQi CMS provides a rich set of string processing filters, such as:

  • replace: Used to replace specific substrings in a string.
  • cut: Used to remove specified characters from a string.
  • upper/lower: Convert a string to uppercase or lowercase.
  • truncatechars/truncatewords: Truncate a string by character or word and add an ellipsis.
  • urlencodeEncode URL parameters. These filters can help you handle and display text content more flexibly in templates.

Related articles

How to combine the `add` filter with the `stampToDate` function to concatenate a formatted date and time string?

When managing content in AnQi CMS, we often need to display dates and times in a specific format.The system provides very convenient template tags and filters to handle these requirements.Today, let's talk about how to combine the `add` filter with the `stampToDate` function to concatenate a formatted date-time string, making our content display more flexible and diverse.### Get to know the `stampToDate` function: Format timestamps First, let's review the `stampToDate` function

2025-11-07

How to efficiently concatenate values of different fields in the custom content model (`archiveParams`) using the `add` filter?

In AnQi CMS, we often encounter the need to combine multiple field values of a custom content model into a text that is more expressive or conforms to a specific display format.For example, you may need to concatenate the "brand" and "model" of the product into a complete product name, or connect the "area code" and "phone number" of the contact.At this time, the `add` filter provided by AnQiCMS combined with the `archiveParams` tag can help us efficiently perform these operations.###

2025-11-07

How to use the `add` filter to dynamically add custom tracking parameters to `tag` links?

In website operation, we often need to track user behavior and evaluate the effectiveness of marketing through different channels.Adding tracking parameters dynamically to website links is an effective method.AnQi CMS is an efficient and flexible content management system that provides a powerful template engine and rich filters, allowing us to easily meet this requirement. Today, let's discuss how to use the `add` filter of Anqi CMS to dynamically add custom tracking parameters to the link of the "Tag".

2025-11-07

Can the `add` filter be used to concatenate array elements processed by the `slice` or `split` filters to form a new string?

When developing templates with AnQi CMS, we often need to flexibly process and display data.This includes string splitting, slicing, and element connection.AnQi CMS provides a rich set of filters (filters) to help us complete these tasks, such as `add`, `slice`, and `split`.Sometimes, we might consider concatenating array elements obtained after processing with `slice` or `split` filters using the `add` filter to form a new string.But is this idea feasible

2025-11-07

Does the `add` filter cause garbled or incorrect output when concatenating Chinese and English mixed strings?

When using AnQiCMS for template development, we often need to concatenate different text content, such as dynamically generated titles, descriptions, etc.At this time, the `add` filter has become a powerful tool in our hands.However, when dealing with mixed Chinese and English strings, many friends may worry: Will such concatenation produce garbled characters or cause program errors?Today, let's discuss this issue in detail.

2025-11-07

In the AnQiCMS template, can a simple counter dynamic display be realized through the `add` filter?

AnQiCMS is an enterprise-level content management system developed based on the Go language, providing strong support for content operators with its efficient and flexible features.In daily content operation and template creation, we often encounter the need to process and dynamically display data, such as adding numbers to list items and calculating totals.Among them, the template filter is an important tool for realizing such needs.Today, let's discuss the `add` filter in the AnQiCMS template to see if it can help us achieve a simple dynamic counter display.###

2025-11-07

How to concatenate `{module}` and `{id}` variables using the `add` filter in Custom URL mode to build a link?

In AnQi CMS, the way websites build links is crucial for SEO and user experience.Although the system provides various predefined pseudo-static rules and automatically generated links, but in certain specific scenarios, we may need to control the URL structure more finely, such as in the custom URL mode, where we concatenate the content model (`{module}`) and content ID (`{id}`) variables to form a unique link.This is not a difficult task, the powerful template engine of Anqi CMS combined with its flexible filter mechanism allows us to easily achieve this goal. Today

2025-11-07

How does the `add` filter assist in building dynamic `<img>` tag `alt` or `title` attribute text to optimize SEO?

In Anqi CMS, every detail of the website is related to the final operating effect, especially in search engine optimization (SEO).We all know that high-quality images can attract users, but if these images are not 'understood' by search engines, their value will be greatly reduced.At this time, the `alt` and `title` attributes of the `<img>` tag are particularly important.They can not only improve the accessibility of the website but are also a key window for search engines to convey the content and context of the image.However, manually writing a unique

2025-11-07