AnQiCMS (AnQiCMS) as an efficient and flexible enterprise-level content management system provides many conveniences in content publishing and SEO optimization. Among them, the URL alias (tokenThe flexible use of parameters is crucial for improving the user experience and search engine optimization of a website. Today, let's delve into how to use the AnQiCMS template, especially inpageDetailLabel it and give full playtokenThe power of parameters.

UnderstandingtokenThe core value of (URL alias)

In AnQiCMS,tokenThis is actually what we set as the 'custom URL' or 'URL alias' for articles, categories, or single pages in the background.This alias is not just for beautifying URLs, it carries important SEO and content management significance.A concise, meaningful URL alias can help search engines better understand the page content and also enhance users' memory and trust in the URL.

AnQiCMS creates content by default and automatically generates a pinyin URL alias based on the page title.Of course, as an operator, we can completely edit and customize this alias according to our own SEO strategy or brand needs.It should be noted that this custom URL alias must be unique throughout the website, and the system will also perform strict validation in the background.

pageDetailLabel: A tool for obtaining single-page information

In AnQiCMS template development,pageDetailTags are the core tools used to obtain detailed information about a single page. Whether it's a company introduction page like "About Us" or "Contact Us", or a customized activity landing page,pageDetailCan help us easily retrieve its title, content, description, and other data.

Generally speaking, when we are on a single page by ourselves,pageDetailThe tag can intelligently obtain all information on the current page without additional parameters. For example, use it directly{% pageDetail with name="Title" %}It can display the title of the current page. And when we want to call a specific single-page content on other pages (such as a block on the homepage), we need to specify it clearly.pageDetailLabel to get which page's data. At this time, we usually use the single page IDidto specify.

tokenThe parameter is inpageDetailApplication of the tag

However, in some cases, relying solely on IDs to call single-page data may not be intuitive, or we may prefer to refer to it through the semantic identifiers of the page. At this point,tokenParameters are particularly important.

tokenParameters allow us to accurately locate and retrieve the details of a page through a single-page URL alias. Its usage is very simple and clear, just inpageDetailthe tag withtoken="你的URL别名"Just do it.

For example, we assume that a URL alias has been created in the backgroundabout-usThe "About Us" single page, and we want to display its introduction in the footer navigation or some module on the homepage, rather than linking directly to it. We can use it in the template like this:

{# 假设有一个URL别名为 "about-us" 的单页面 #}
{% pageDetail aboutUsPage with token="about-us" %}
    <div class="footer-about">
        <h3>{{ aboutUsPage.Title }}</h3>
        <p>{{ aboutUsPage.Description }}</p>
        <a href="{{ aboutUsPage.Link }}">了解更多我们</a>
    </div>
{% endpageDetail %}

In this code block,aboutUsPageThis variable will carry the URL aliasabout-usAll the data on the single page. We can then easily extract the title, description, link, and other information for display.

Give another example, if our website has a page namedprivacy-policyPrivacy Policy page, and it needs to reference the full content of the user registration agreement (not just a link), usingtokenParameters can be called very conveniently and clearly:

{# 假设有一个URL别名为 "privacy-policy" 的单页面,用于展示隐私政策 #}
<div class="registration-agreement">
    <h2>用户注册协议</h2>
    <p>请您仔细阅读本协议,并勾选同意...</p>

    <h3>隐私政策声明</h3>
    {% pageDetail privacyPolicy with token="privacy-policy" %}
        {# 在这里调用隐私政策页面的内容,并使用 |safe 过滤器确保HTML内容正确渲染 #}
        <div class="privacy-content">
            {{ privacyPolicy.Content|safe }}
        </div>
    {% endpageDetail %}

    <p>...通过注册即表示您同意以上所有条款。</p>
</div>

In this way, even if the ID of the privacy policy page changes in the future, as long as its URL aliasprivacy-policyKeep unchanged, we do not need to make any modification to the reference code in the template, which greatly improves the robustness and maintainability of the template.

Actual application scenarios and advantages

totokenParameter integrationpageDetailThe use of tags can bring various benefits to website operation:

  1. Improving code readability and maintainability:Direct pass.tokenCiting the page is more intuitive than using a numeric ID, making the intent of the template code clear, even for non-developers can see at a glance which page content is being called, reducing the maintenance cost thereafter.
  2. Enhance template flexibility:Whether in the global public area (such as the footer, sidebar), or in a specific content module, we can flexibly call any specified single page content without worrying about the change of page ID.
  3. SEO-friendly development: tokenIt is a SEO-friendly URL alias itself, referring to content in the template, which also indirectly strengthens the association between content and semantic URL.

As seasoned website operators, we know that content updates and flexible template adjustments are the norm in our daily work. Proficient in masteringpageDetailLabel collaborationtokenThe use of parameters undoubtedly allows our content operation to be more skillful, ensuring the stability and efficiency of the front-end display of the website.


Frequently Asked Questions (FAQ)

  1. Question: When should I prioritize the use oftokeninstead ofidCall a single page?Answer: When you want the code to be more semantically meaningful and readable, and you are sure that the single page URL alias (token) will be more stable than its database ID, use it preferentiallytokenFor example, when calling some fixed functional pages (such as "About Us", "Terms of Service") across pages, usetokenIt makes the template code clearer and reduces the risk of failure due to changes in background IDs. However, it is important to notetokenThe uniqueness throughout the site ensures that there is no confusion

  2. Question: If I settokenDoes the single page corresponding to the parameter not exist, will the template report an error?Answer: Usually, iftokenthe single page specified by the parameter does not exist,pageDetailThe tag will not directly cause the template rendering error to break. It will only return an empty data object. This means that in{% pageDetail yourPageData with token="non-existent-token" %}...{% endpageDetail %}the block inside,yourPageDataThe variable will not contain any valid page information, therefore the internal references{{yourPageData.Title}}of the fields will be displayed as blank. To avoid this situation, you can add to the template{% if yourPageData %}This conditional judgment ensures that rendering only occurs when page data exists.

  3. Question:tokenIs the 'URL alias' referred to by the parameter the same as the 'custom URL' I set in the AnQiCMS backend?Answer: Yes, it is the same concept entirely.tokenThe parameter in the AnQiCMS template tag is used to refer to the 'custom URL' you set for a single page (as well as articles, categories, and other content) in the background