How to use the `add` filter to build dynamic SEO-friendly URL paths in the Anqi CMS template?

Calendar 👁️ 62

In the template creation of AnQi CMS, flexible and SEO-friendly URL paths are the key to improving the website's search engine performance. Although AnQi CMS provides powerful static rule configuration capabilities in the background, by defining such/{module}-{id}.htmlGenerate static URLs using a pattern, but in certain specific scenarios, we may need to have more dynamic and fine-grained control or combination of the local URL paths within the template, in order to meet unique business needs or marketing strategies. At this point,addThe filter has become a very practical auxiliary tool.

AnQiCMS URL path SEO basics

It is very important to understand how Anqi CMS builds SEO-friendly URLs.The core of AnQi CMS lies in its powerful pseudo-static rule management feature.In the background, we can set a unified URL structure for document detail pages, category list pages, single pages, etc., for example:

  • Document details:archive===/{module}/{id}.htmlorarchive===/{module}/{filename}.html
  • Category list:category===/{module}/{catid}/orcategory===/{module}/{catname}/

These rules define the basic structure of the website URL, search engines will use these clear structures to crawl and index pages. The system will automatically alias the content model names{module})、Document ID({id})、File Name({filename}), classification ID ({catid})、Category Name({catname}Fill dynamic data into the preset URL pattern to generate a static access path.This greatly simplifies the work of website administrators while ensuring the structurization and readability of URLs.

addWhat is a filter?

In AnQi CMS template syntax,addA filter is a very basic but powerful tool, mainly used for performing addition operations on numbers or strings.Just like in many programming languages, when used with numbers, it performs mathematical addition;When used for strings, it concatenates two strings.

For example:

  • {{ 5|add:2 }}Will be displayed7
  • {{ "安企"|add:"CMS" }}Will be displayed安企CMS

This seemingly simple function, in scenarios related to URL paths, can still show unexpected flexibility.

addThe practical scenarios of filters in URL construction

Although the pseudo-static rules of AnQi CMS define the structure of most core URLs on the website, butaddThe filter provides us with the ability to "micro-tune" or "extend" these URLs at the template level, especially suitable for the following situations:

  1. Dynamically append query parameters:Marketing campaigns, A/B testing, or user behavior tracking often require appending dynamic query parameters to the URL, such as?utm_source=.../?ref=...These parameters are usually not part of the static rule, but are crucial for data analysis. We can utilizeaddThe filter dynamically appends these parameters to the end of articles, products, and other links.

    Example: Add UTM tracking parameters to the article linkSuppose we have an article link variableitem.LinkIts value is/article/anqi-cms-intro.htmlWe want to add UTM tracking parameters.

    <a href="{{ item.Link|add:'?utm_source=newsletter&utm_medium=email' }}">阅读详情</a>
    {# 生成的URL可能类似:/article/anqi-cms-intro.html?utm_source=newsletter&utm_medium=email #}
    

    If the parameter value itself is dynamic:

    {% set campaign_source = "wechat" %}
    {% set article_id = item.Id %}
    <a href="{{ item.Link|add:'?source='|add:campaign_source|add:'&article_id='|add:article_id }}">查看文章</a>
    {# 如果item.Link是/article/123.html,article_id是123,campaign_source是wechat,则生成:/article/123.html?source=wechat&article_id=123 #}
    
  2. Build a custom URL fragment for specific business needs:In some non-standardized pages or functional modules, it may be necessary to dynamically generate a URL path segment based on multiple data fields. Although it is not recommended to use this complex logic for the core content URL of a website (pseudo-static rules should be prioritized), it is used in some special auxiliary pages, such as report download links, specific filtering result pages, etc.addThe filter can flexibly combine different variables to form a path.

    Example: Build a download link for a composite query.Assuming we have a page to download reports, the path needs to be dynamically generated based on the report type and year.

    {% set report_type = "annual" %}
    {% set report_year = "2023" %}
    <a href="/downloads/reports/{{ report_type|add:'-'|add:report_year|add:'.pdf' }}">下载{{ report_year }}年{{ report_type }}报告</a>
    {# 生成的URL:/downloads/reports/annual-2023.pdf #}
    

    here,addThe filter effectively connects strings, variables, and delimiters to form a complete URL.

  3. Auxiliary concatenation for URL alias or SLUG:When the Anqi CMS generates URL aliases in the background, it usually generates pinyin or English based on the title. However, in the template, if you need to further concatenate these aliases, for example, by adding a language prefix or a specific identifier, addThe filter can also do it

Related articles

How to use the `add` filter to dynamically add 'Yuan' or a specific currency symbol after the product price?

When managing website content, especially when it involves product display, we often need to present price and other numerical information in a more user-friendly manner.单纯显示一串数字,比如 `199`,往往不够直观,如果能自动加上货币符号,比如 `199元` 或 `$199`,就能大大提升信息的可读性和专业性。AnQiCMS (AnQiCMS) with its flexible template system makes it very simple to meet such requirements, and the key to this is the clever use of the `add` filter.### Understand `add`

2025-11-07

What is the practical difference in applying the `add` filter and the `stringformat` filter in template string concatenation?

In the AnQi CMS template world, flexibly handling strings is an indispensable skill for building dynamic web pages.Among them, the `add` filter and the `stringformat` filter can help us concatenate or combine strings, but their design philosophy and application scenarios are obviously different.Understanding these differences allows us to make more informed choices when developing templates, resulting in more efficient and readable code.### `add` filter: A concise and intuitive concatenation tool `add`

2025-11-07

How to dynamically add 'Read More' link text to each title on the AnQiCMS article list page?

When managing and operating a website, the article list page is an important entry for users to browse content and discover information.To enhance user experience, clearly guiding visitors to enter the article details, it is a common practice to dynamically add a "Read More" or "View Details" link text to each title in the list.AnQiCMS (AnQiCMS) provides a powerful and flexible template system, allowing us to easily achieve this feature.

2025-11-07

How do you handle the case when one of the variables is `nothing` or `nil` while using the `add` filter, and what will be the output result?

In AnQiCMS template development, we often need to perform simple addition operations or string concatenation, the `add` filter is created for this purpose.It is very convenient to use, and can intelligently handle addition of numbers and concatenation of strings.If you give it two numbers, it will perform mathematical addition;If you give it two strings, it will concatenate them.Even if it is a mixture of numbers and strings, AnQiCMS will try to make a reasonable conversion and output the result.For example, add numbers: twig {{ 5|add:2 }} {#

2025-11-07

How to use the `add` filter in a `for` loop to dynamically generate a unique `id` or `class` attribute for list items?

In AnQi CMS template development, we often need to handle the display of dynamic lists.Whether it is an article list, product display, or other content block, dynamically generating a unique `id` or `class` attribute for each item in the list is particularly important in order to achieve finer style control, JavaScript interaction, or to ensure the uniqueness of page elements.Today, let's talk about how to cleverly use the `add` filter in the `for` loop of AnQiCMS to achieve this goal.### Understanding the demand for dynamic attribute generation Imagine that

2025-11-07

Can the `add` filter be used to concatenate the website name and footer copyright information obtained from the `system` tag?

In website operation, we often need to finely control the display of page content, especially those global information that needs to be repeatedly displayed throughout the website, such as the website name, footer copyright, and so on.AnQiCMS (AnQiCMS) provides powerful template tags and filters to help us flexibly handle these requirements.Today, let's talk about a very practical scenario: Can the `add` filter of AnQi CMS be used to concatenate the website name and footer copyright information obtained from the `system` tag?The answer is affirmative, and this method is both intuitive and efficient.

2025-11-07

How to concatenate the area code and phone number in the contact (`contact` tag) using the `add` filter?

It is crucial to clearly and effectively display contact information when operating your website.AnQiCMS (AnQiCMS) with its flexible template engine and powerful tag system, allows you to easily achieve various complex display needs.Today, let's talk about a common but somewhat tricky requirement: how to concatenate the area code and phone number in the contact information using the `add` filter to make your phone number clear at a glance.Why do you need to concatenate the area code and phone number?

2025-11-07

When handling floating-point number addition with the `add` filter, should special attention be paid to its calculation accuracy?

When using AnQi CMS for website content management, template tags and filters are tools we often use, greatly enhancing the flexibility of content presentation.Among them, the `add` filter allows us to perform addition operations of numbers or strings in the template, which is very convenient in many scenarios.However, when it comes to adding floating-point numbers (which are decimal numbers), some users may wonder: Does the `add` filter need to pay special attention to its calculation accuracy when handling such calculations?

2025-11-07