In website operation, a clear, semantically meaningful URL structure not only improves user experience but is also the foundation of search engine optimization.For AnQiCMS users, it is a very practical skill to flexibly build 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.

The basic URL 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 the URL structure according to business needs, for example, the document detail page can use/{module}/{id}.htmlor/{module}/{filename}.htmlSuch a pattern. Here{module}Represents a content model (such asarticle/product){id}is the unique ID of the content,{filename}and then is the custom URL alias. Category pages, tag pages, and so on also have a similar structure.

These pseudo-static rules are configured under "Function Management" in the background under "Pseudo-static Rules".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 multiple combinations, we need to use URL query parameters (Query Parameters) to achieve this, and we need to pay special attention to the escaping of parameters.

Build a URL with dynamic parameters

In AnQiCMS templates, we often need to dynamically generate URLs based on user selection or backend data. This usually involves adding to the basic URL path.?key1=value1&key2=value2Such a query string. Here are some common scenarios for dynamic parameter construction:

  1. Intrinsic links based on documents/categorization/tags:AnQiCMS various list tags (such asarchiveList/categoryList/tagList) While outputting content in a loop, itsitem.Linkfield already contains a friendly URL generated according to the static rule. For example:

    {% archiveList archives with type="list" limit="10" %}
        {% for item in archives %}
            <a href="{{ item.Link }}">{{ item.Title }}</a>
        {% endfor %}
    {% endarchiveList %}
    

    Here{{ item.Link }}It is usually a static or pseudo-static path processed by the system, it does not contain query parameters, but it is itself a dynamically generated URL.

  2. Add search keywords or other single query parameters:When we need to add search keywords to an existing URLqOr other custom parameters can be implemented through string concatenation.For example, on a category list page, we want to add a search box: “`twig {# Assuming the current category link is category.Link, the search box input value is searchQuery #} {% set currentCategoryLink = category.Link %} {% set searchQuery = “AnQiCMS template” %} {# This is the user's search term #}

    <a href=“{{ currentCategoryLink