How to get the full URL address of the current page being accessed in the template?

Calendar 81

In-depth analysis: How to cleverly obtain the full URL address of the current page in Anqi CMS template?

As an experienced website operation expert, I know that accurately obtaining the complete URL address of the current page is a common and important need in daily work. Whether it is to set standardizedcanonicalTags, sharing to social media, passing parameters, or performing data statistics, the accurate URL of a page is core information. In AnQiCMS, an efficient and SEO-friendly content management system, there is no direct term calledcurrent_page_urlSuch a global variable, but through its flexible template tag system, we can still easily and accurately obtain the required information.

The AnqiCMS uses a template engine syntax similar to Django, emphasizing simplicity and practicality.It is designed intelligently to make the generation and management of content URLs simple and powerful, which is attributed to its deep integration with pseudo-static rules and content models.Therefore, to obtain the URL of the current page, we need to understand the URL construction logic of AnQiCMS and make good use of the various tags it provides.

Understand the URL construction philosophy of Anqi CMS

The highlight of AnQi CMS is its automatic and optimized URL processing.The system will dynamically generate the page access address based on the pseudo-static rules you configure in the background (such as numeric patterns, model naming patterns, or custom patterns), as well as the ID, alias, category, and other information of the content itself.This means that in most cases, you do not need to manually concatenate complex URLs, the system has already prepared standardized, SEO-friendly links for you.

This "out-of-the-box" link generation mechanism greatly simplifies the work of template developers. In the template, when you refer to some content (whether it is an article, product, category, or single page), you can usually directly go through its built-inLinkTo obtain the complete access path of the property.

The way to obtain the URL of the content page.

In Anqi CMS, for the purpose of.Content detail page./Category list page/single pageas well asTab pagePages driven by content models can be accessed relatively directly. The system will retrieve the corresponding object based on the context of the current page, such asarchive/category/page/tag)inject into the template environment, you just need to access these objects'Linkproperties.

For example, on the article detail page (for examplearchive/detail.htmlOr customize the article template) To get the current article URL, you can use it directly:

<a href="{{ archive.Link }}">访问当前文章</a>

HerearchiveThe variable represents the article object being accessed, and.LinkIt is the automatically generated complete access path (usually a path relative to the root directory of the website, or even a complete absolute path under some configurations).

Similarly, the principle is consistent in other types of pages:

  • Category page (category/list.htmlor custom category template):
    
    <a href="{{ category.Link }}">当前分类链接</a>
    
  • Single page (page/detail.htmlor custom single page template):
    
    <a href="{{ page.Link }}">当前单页面链接</a>
    
  • Tag detail page (tag/detail.html):
    
    <a href="{{ tag.Link }}">当前标签链接</a>
    

When you traverse the content in a list loop, obtaining the URL of each list item is also achieved byitem.Linkwhich is implemented. For example, in an article list:

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

Hereitemeach article object in the loop is,.LinkIt provided the access link for each article.

Build a complete URL: Basics and Variables

Althougharchive.LinkAttributes are usually already provided with a sufficiently complete path to the page, but in some special cases, you may need to obtain a URL that includes the protocol header and the full domain nameAbsolute URLfor example, used forhreflangTags, cross-domain API calls, or client-side JavaScript logic.

Anqi CMS passedsystemTags provide a series of basic configuration information for websites, including the root address of the website.BaseUrl. You can get it like this in the template:

{% system siteBaseUrl with name="BaseUrl" %}
<p>网站基础地址是: {{ siteBaseUrl }}</p>

BaseUrlIt usually returns the website address configured in the background “Global Settings”, for examplehttps://www.example.com. If you need to convert relative paths to absolute paths, you can use them togetherBaseUrl:

{% system siteBaseUrl with name="BaseUrl" %}
{% archiveDetail currentArchive with name="Link" %}
<a href="{{ siteBaseUrl }}{{ currentArchive }}">绝对文章链接</a>

However, please note: Due to AnQiCMS'sLinkProperties often already include the domain name, and direct concatenation may lead to duplicate URLs. Usually,archive.LinkThe URL that has already been returned is one that conforms to SEO standards and can be used directly. The safest way is to use the content object built-in first.LinkProperty.

Skillfully use auxiliary tags and scenario practice

For more professional URL requirements, AnQi CMS also provides powerfultdkThe tag is especially suitable for handling page SEO meta information, including canonical links (Canonical URL).

Set the canonical link (Canonical URL)

Set at the top of the pagecanonicalTags are an important part of SEO, it

Related articles

Can I view the path of the template file on the server directly through the AnQiCMS background online template editing feature?

As an experienced website operations expert, I am well aware of the importance of template management for website personalization and operational efficiency.AnQiCMS (AnQiCMS) boasts its high efficiency and flexibility, which is favored in the content management field. Its template editing function on the back-end provides great convenience for content operators.TodayUnlocking AnQiCMS Template Path

2025-11-06

Where is the AnQiCMS scheduled task script (such as `start.sh`) usually stored?

As an experienced website operations expert, I know that the stable operation of every CMS system is inseparable from the silent support of its core components.Today, let's talk about a seemingly simple but crucial file in AnQiCMS - the scheduled task script `start.sh`, where is it hidden, and what role does it play in the daily operation and maintenance of AnQiCMS.--- ### Revealing AnQiCMS: The Hidden Location of the `start.sh` Scheduled Task Script For AnQiCMS users, whether it is for the first deployment or daily maintenance

2025-11-06

How to view the template file path of the system's default 404, 500 error pages and shutdown prompt page?

As an experienced website operations expert, I know that in the daily operations of a website, we always hope for everything to go smoothly, but unexpected situations are always hard to avoid.Whether it is the user visiting a non-existent page, or the backend server experiencing an occasional failure, or the website needing temporary maintenance, how to elegantly handle these special situations is directly related to user experience and brand image.AnQiCMS is well-versed in this, providing a highly flexible template mechanism to customize these key pages.Today, let's delve into how to find and personalize your 404 in AnQiCMS

2025-11-06

How to specify the file path of the public code snippet included when using the `include` tag in the template?

As an experienced website operations expert, I know the importance of an efficient content management system (CMS) for website operations.AnQiCMS (AnQiCMS) provides a solid foundation for us to build various websites with its flexibility and powerful template features.Today, let's talk about one of the very practical features that can greatly improve template development efficiency - the `include` tag, especially how the file path is specified when referencing common code snippets, which is often a place where beginners and even experienced developers may feel confused.Why choose to use

2025-11-06

Why is my custom URL alias not working, what path configurations should I check?

As a senior website operations expert, I fully understand the confusion and anxiety you feel when the custom URL alias you carefully set up does not work as expected.A clean, meaningful URL structure is crucial for a website's SEO performance and user experience.AnQiCMS (AnQiCMS) was designed with flexibility in URLs and SEO friendliness in mind, but to make these features work, we do indeed need to ensure that the configuration of several key paths is correct.Today, let's delve into the discussion when your custom URL alias is "**"

2025-11-06

What is the default URL structure of the article detail page in AnQiCMS?

As an experienced website operations expert, I am well aware of the importance of the URL structure of a website for SEO optimization and user experience.In AnQiCMS, a content management system committed to providing efficient and customizable solutions, understanding the URL structure of its article detail page is the foundation for content operation and SEO layout. Let's delve into how the default URL structure of the article detail page in AnQiCMS is designed.--- ## Reveal the default URL structure of AnQiCMS article detail page: Flexible and

2025-11-06

How to view the URL link address of a specific category?

In AnQiCMS (AnQiCMS), managing and obtaining the URL link address of categories is a fundamental and important task in website operation.It is crucial to clearly know how to view and use these links, whether it is for content organization, search engine optimization (SEO), or user navigation.As a content management system dedicated to providing efficient and customizable solutions, AnQiCMS offers flexible and intuitive options in this regard.### Understanding the Basic Structure of AnQiCMS Category URLs The category URL in AnQiCMS is not fixed

2025-11-06

When customizing the content model, which page paths will be affected by the `URL Alias` field?

## Unveiling AnQi CMS Custom Content Model: How Does the "URL Alias" Affect Your Website Page Path??As an experienced website operations expert, I am well aware of the importance of the page path (URL) for user experience and search engine optimization (SEO).A clear, meaningful, and easy-to-understand URL that not only helps users navigate the website better but also effectively improves the crawling efficiency and keyword ranking of search engines.

2025-11-06