How does the AnQiCMS template display the base URL address of the current website?

Calendar 👁️ 69

In website operation and template development, accurately obtaining and displaying the basic URL address of the current website is a very basic but important requirement.It is crucial to understand how to flexibly call the basic URL of the website in AnQiCMS templates, whether it is for correctly loading static resources of the website (such as CSS, JavaScript, and images), building dynamic internal links, or generating Canonical URL in accordance with SEO standards.AnQiCMS as an efficient and customizable content management system fully considers this requirement and provides a simple and intuitive method for handling.

Why is the base URL of the website so important?

The basic URL of the website, which is also known as the root domain or main domain, representing the starting point of the website on the internet. Referring to this basic URL in AnQiCMS templates has several undeniable benefits:

  1. Ensure resources are loaded correctly: When referencing CSS, JavaScript files, or images in a template, if you use a relative path, problems may arise in some complex URL structures.Use the base URL to construct an absolute path, which ensures that these resources can be loaded correctly on any page.
  2. Improve SEO performance: A search engine prioritizes identifying clear and consistent URL structures when crawling and indexing websites.By using a unified base URL to construct internal links, it helps to avoid duplicate content issues and provides a more friendly crawling path for search engines.
  3. Convenient for multi-site management:AnQiCMS supports multi-site management, different sites may have different base URLs.In the template, dynamically calling the base URL of the current site can avoid hardcoding and make the template more flexible when reused across different sites.
  4. Dynamically generate navigation and links: Many website navigation menus, breadcrumb navigation, friend links, and others need to point to the internal pages of the website.Dynamically retrieve the base URL, which can facilitate the concatenation of complete internal links, improving the maintainability and scalability of the template.

Method to obtain the base URL in AnQiCMS templates

In AnQiCMS, the basic URL address of the current website is mainly obtained through built-insystemtags and theirBaseUrlto implement the field.

1. KnowledgesystemTag

systemThe tag is a powerful global configuration information call tool provided by AnQiCMS. It can help us obtain various system-level parameters configured in the background "Global Function Settings", including website name, Logo, filing number, copyright information, etc., of course, including the main character of today - the website homepage addressBaseUrl.

2. Get the basic URL tag of the website

To get the basic URL of the website in the template, you can use the following concise tag:

{% system with name="BaseUrl" %}

This label will directly output the content of the "Website Address" configured in the "Global Function Settings" in the background of the current website.

If you are accustomed to assigning the result of a label to a variable for subsequent use or further processing (for example, combining with other filters), you can also do so:

{% system baseUrl with name="BaseUrl" %}
{{ baseUrl }}

at this point,baseUrlThe variable will store the base URL of the website, which you can reference at any position in the template. If you are concerned that the URL may contain special characters that could cause parsing issues (although AnQiCMS usually handles security), you can add it when outputting the variable.|safeThe filter is also a good habit:

{% system baseUrl with name="BaseUrl" %}
{{ baseUrl|safe }}

3. Actual application cases

Understood how to getBaseUrlAfter that, let's take a look at its specific application scenarios in the template:

a. Load static resources

in the template's<head>Partially import CSS files, or in<body>load JavaScript files and images:

<head>
    <!-- 引入CSS文件 -->
    <link rel="stylesheet" href="{% system with name="BaseUrl" %}/public/static/css/style.css">
    <!-- 设置网站Favicon -->
    <link rel="icon" href="{% system with name="BaseUrl" %}/favicon.ico" type="image/x-icon">
</head>
<body>
    <!-- 加载图片 -->
    <img src="{% system with name="BaseUrl" %}/uploads/logo.png" alt="网站Logo">
    <!-- 引入JavaScript文件 -->
    <script src="{% system with name="BaseUrl" %}/public/static/js/main.js"></script>
</body>

It should be noted that if your static files are located in the current template directory (usually/template/您的模板名/public/static/), then useTemplateUrlthe label will be more accurate and recommended:

<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">

TemplateUrlThe tag directly outputs the root directory address of the static files of the currently used template, which is more convenient for referencing static resources within the template.

b. Build internal links

In the navigation menu, article list, or any place where you need to jump to the internal page of the website,BaseUrlit can be used.

<nav>
    <a href="{% system with name="BaseUrl" %}">网站首页</a>
    <a href="{% system with name="BaseUrl" %}/about-us.html">关于我们</a>
    <a href="{% system with name="BaseUrl" %}/contact.html">联系我们</a>
</nav>

<!-- 文章详情页中的返回列表链接 -->
<a href="{% system with name="BaseUrl" %}/news-list.html">返回新闻列表</a>

c. Generate Canonical URL (SEO Optimization)

Although AnQiCMS provides a dedicatedtdktag to obtain the canonical linkCanonicalUrlBut in some custom scenarios, you may need to build it manually. In this case,BaseUrlis an important part of building a complete URL:

{%- tdk canonical with name="CanonicalUrl" %}
{%- if canonical %}
<link rel="canonical" href="{{canonical}}" />
{%- else %}
<link rel="canonical" href="{% system with name="BaseUrl" %}{{ request.path }}" />
{%- endif %}

Hererequest.pathUsed to obtain the relative path of the current page, combinedBaseUrlto form a complete standard URL.

4. Obtain the base URL in a multi-site scenario.

AnQiCMS's multi-site feature is one of its highlights. If you manage multiple sites and need to refer to the base URL of a site's template,other sites,systemThe tag also provides corresponding support. You just need to go throughsiteIdSpecify the ID of the target site with the parameter:

{# 获取站点ID为2的网站基础URL #}
{% system otherSiteBaseUrl with name="BaseUrl" siteId="2" %}
<p>另一个网站的地址是: {{ otherSiteBaseUrl|safe }}</p>

Please note if:siteIdThe parameter is not specified,systemThe tag will get by defaultThe current visited siteThe base URL of.

Practical suggestions

  • Ensure the background settings are accurate: The value of the website base URL comes from the "Global Function Settings" of AnQiCMS background.

Related articles

How to display the filing number and copyright information at the bottom of the AnQiCMS website?

In website operation, the information display at the bottom of the website, especially the filing number and copyright statement, is not only an embodiment of website compliance, but also an important way to convey trust and professionalism to visitors.For websites built using AnQiCMS, it is a fundamental operation to display these key information flexibly and efficiently at the bottom of the website, which is the basis for improving user experience and meeting legal and regulatory requirements.

2025-11-07

How to dynamically retrieve and display the website logo image address in AnQiCMS templates?

In web design, the logo is not just a symbol of the brand, it is also the core of the website's recognition.For a content management system like AnQiCMS, the ability to flexibly call and display the website logo in templates is the key to improving operational efficiency and maintaining brand consistency.The good news is that AnQiCMS provides a very intuitive and powerful way to dynamically retrieve and display the image address of your website's Logo, allowing you to easily manage your brand image without touching the core code.

2025-11-07

How to display the system name configured in the background of AnQiCMS website?

Conveniently display the system name configured in the AnQiCMS website The system name of the website is a core component of its online identity, it is not just a simple name, but also a key to brand image, search engine optimization (SEO) and user identification.For AnQiCMS users, displaying the system name configured in the background on the website frontend can ensure consistency of website information, enhance user experience, and improve search engine friendliness.

2025-11-07

How to display the title and link of the previous and next articles on the article detail page?

In website operation, the 'Previous' and 'Next' navigation function on the article detail page not only effectively improves the user's reading experience and guides them to continue browsing more content, but also has a positive impact on the website's SEO performance by building internal links.For AnQiCMS users, implementing this feature is simple and efficient.AnQiCMS provides a straightforward and powerful template tag system, making it easy to display the titles and links of the previous and next articles on the article detail page.You do not need to perform complex programming or database queries

2025-11-07

How to get and display the contact phone number and address set in the AnQiCMS template?

It is crucial to clearly and accurately display contact information in website operations to enhance user trust and promote communication and exchange.AnQiCMS provides a convenient backend setting and template calling mechanism, allowing you to easily manage and display this key information.This article will introduce in detail how to configure contact phone numbers and addresses in the AnQiCMS backend, as well as how to obtain and flexibly display this content in website templates.--- ### One, configure the contact phone number and address in the AnQiCMS backend Firstly, we need to configure in AnQiCMS

2025-11-07

How to safely display user-entered HTML content (such as article text) in AnQiCMS templates?

In website content operations, displaying user input information is one of the core functions, especially like the main text of articles that may contain rich formatting content.However, how to safely and accurately present these user-entered HTML content on the website while preventing potential security risks (such as cross-site scripting XSS attacks) is a problem that every website operator needs to think deeply about.AnQiCMS provides flexible and powerful tools for template design and content processing to meet this challenge.### AnQiCMS's default security mechanism: automatic escaping is the cornerstone AnQiCMS

2025-11-07

How to display the article list on the AnQiCMS website and support sorting by publish time in descending order?

When running a website, effectively displaying a content list is a key factor in attracting visitors and enhancing user experience.For friends using AnQiCMS, the system provides very flexible and powerful template functions, which can easily meet various complex content display needs.Today, let's discuss how to display the article list on the AnQiCMS website, ensuring that the articles are sorted from the most recent to the oldest in publication time, while also supporting friendly pagination features.AnQiCMS's template system borrows the syntax of Django template engine

2025-11-07

How to implement pagination for article lists in AnQiCMS templates?

Good, as an experienced website operations expert, I know that implementing pagination for the article list in AnQiCMS not only improves user experience and makes content browsing smoother, but also helps with search engine optimization, allowing website content to be indexed better.Next, I will combine the AnQiCMS template mechanism and explain in detail how to easily implement this feature.

2025-11-07