In website operation, a clear, semantic URL structure not only improves user experience but also serves as the foundation for search engine optimization.For AnQiCMS users, it is a very practical skill to flexibly construct URLs with multiple dynamic parameters in templates and ensure that these parameters are properly escaped.This article will delve into the methods of achieving this goal in the AnQiCMS template.
URL basics and pseudo-static in AnQiCMS
AnQiCMS as a SEO-friendly content management system, its powerful pseudo-static function is the foundation for building elegant URLs. The system allows us to customize URL structures according to business needs, for example, the document detail page can use/{module}/{id}.htmlor/{module}/{filename}.htmlsuch a pattern. Here{module}represents the content model (such asarticle/product){id}is the unique ID of the content{filename}and this is the custom URL alias. Category pages, tag pages, etc., also have a similar structure.
These pseudo-static rules are configured under 'Function Management' -> 'Pseudo-static Rules' in the background.Although these rules define the skeleton of the URL, when we need to pass additional dynamic data in the URL, such as search keywords, filtering conditions, or make multiple combinations, we need to use URL query parameters (Query Parameters) to achieve this, and we must pay special attention to parameter escaping.
Build a URL with dynamic parameters
In AnQiCMS templates, we often need to dynamically generate URLs based on user selections or backend data. This usually involves adding to the basic URL path after?key1=value1&key2=value2Such a query string. The following are some common scenarios for constructing dynamic parameters:
Intrinsic links based on document/categorization/label:Various list tags in AnQiCMS (such as)
archiveList/categoryList/tagListIn the loop output, itsitem.Linkfield already contains a friendly URL generated according to the pseudo-static rules. For example:{% archiveList archives with type="list" limit="10" %} {% for item in archives %} <a href="{{ item.Link }}">{{ item.Title }}</a> {% endfor %} {% endarchiveList %}Here are the
{{ item.Link }}It is usually a static or pseudo-static path processed by the system, which does not include query parameters, but itself is a dynamically generated URL.Add search keywords or other single query parameters:When we need to add search keywords to an existing URL
qWhen other custom parameters are used, string concatenation can be implemented.href="{{ currentCategoryLink