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}.htmlUsing patterns to generate static URLs, but in some specific scenarios, we may need to have more dynamic and fine-grained control or combination of local URL paths within the template to meet unique business requirements or marketing strategies. At this point, addFilter has become a very practical auxiliary tool.
AnQiCMS URL Path SEO Basics
It is very important to understand how to build SEO-friendly URLs in Anqi CMS.The core of Anqi CMS lies in its powerful pseudo-static rule management function.
- 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 crawl and index pages based on this clear structure. The system will automatically convert content model aliases ({module})、document ID({id})、file name({filename}), category ID ({catid})、category name({catname}) etc. dynamic data is filled into the preset URL pattern to generate a static access path.This greatly simplifies the work of website administrators, while ensuring the structuralization and readability of URLs.
addWhat is a filter?
In the template syntax of AnQi CMS,addA filter is a very basic but powerful tool, mainly used for performing concatenation operations on numbers or strings.Just as in many programming languages, when used with numbers, it performs mathematical addition; when used with strings, it concatenates the two strings.
For example:
{{ 5|add:2 }}Will be displayed7{{ "安企"|add:"CMS" }}Will be displayed安企CMS
This seemingly simple feature, in the context of URL path-related scenarios, can exert unexpected flexibility.
addFilter practical scenarios in URL construction
Although the pseudo-static rules of the Aanqi CMS define the structure of most of the core URLs of the website,addThe filter provides us with the ability to 'tune' or 'extend' these URLs at the template level, especially suitable for the following situations:
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 rewrite rule, but are crucial for data analysis. We can useaddFilter adds these parameters dynamically to the end of links to articles, products, etc.Example: Add UTM tracking parameters to article linksSuppose we have a variable for an article link
item.Linkwith the value/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 #}Build a custom URL fragment for specific business requirements.In some non-standardized pages or feature 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 URLs of a website (pseudo-static rules should be preferred), it is sometimes used in special auxiliary pages such as download links for reports, pages with specific filtering results, etc.
addThe filter can flexibly combine different variables to form a path.Example: Build a download link for a composite queryThe page for downloading reports needs to dynamically generate paths 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.Auxiliary concatenation of URL alias or SLUG:The "auto" translated to "English" is "Automatically generated by the AnQi CMS in the background. It usually generates pinyin or English for the alias based on the title. However, in the template, if further concatenation is required for these aliases, for example, adding a language prefix or a specific identifier,
addThe filter can also be assigned