Using AnQiCMS content model URL alias (token):The wisdom of accurately obtaining information

As a senior website operation expert, I fully understand the importance of an efficient and customizable content management system for corporate websites and content operation teams.AnQiCMS with its efficient architecture in Go language and versatile functions, is gradually becoming a powerful assistant for many operators.In daily content management, we not only pursue the high-quality presentation of content, but also need efficient data retrieval and management.token).

In AnQiCMS, the content model is the foundation we build various content types upon, whether it's articles, products, events, or single pages, all of which rely on the flexible definition of the content model. It is closely related to the URL alias, which is what we commonly refer to astokenIt plays the role of the 'ID card' of the content on the web page.It not only makes our URL address more readable and friendly to search engines, but more importantly, it provides us with a convenient way to directly locate and obtain specific model information without using ID.

URL alias (tokenThe importance of is not just beauty

We all know that a clear, meaningful URL is crucial for SEO and user experience.AnQiCMS was designed with this in mind from the very beginning.When you create articles, categories, single pages, or even the content model itself, the system will automatically generate a pinyin-based URL alias based on the title you enter.Of course, if you are not satisfied with the automatically generated alias, you can completely modify it manually to ensure that it reflects the content theme and includes core keywords, thereby better supporting SEO optimization.It is worth noting that in order to avoid link conflicts and unnecessary troubles, the manually set URL alias must ensure the uniqueness across the entire site.If duplicates occur, AnQiCMS will automatically add random numbers at the end to ensure its uniqueness.

This custom URL alias mechanism, combined with the pseudo-static rule management function of AnQiCMS, can make your website URL structure more standardized, for example, you can set the document detail page to/{module}-{filename}.htmlor/{catname}/{filename}.html,“ here is the{filename}通常就对应着我们所说的URL别名或token.

However,tokenThe value is far more than that.It is not only an aesthetically pleasing part of the URL, but also a powerful parameter in the AnQiCMS template tags, allowing us to obtain the specified content information in a more intuitive and business-relevant way.

核心机制:URL别名(token)如何精准获取信息

In AnQiCMS template development, when we want to obtain detailed information of a specific document, category, single page, or the model itself, we usually think of using its numeric ID. But when the content ID changes or we want to use a more semantic identifier, token参数就派上了大用场。AnQiCMS提供了一系列详情标签,它们都支持通过 English 来指定要获取的内容。token参数来指定要获取的内容。

这些标签包括:

  • archiveDetail:Used to obtain detailed information of a specific document (article, product, etc.).
  • categoryDetail:Used to obtain detailed information of a specific category.
  • pageDetail:Used to obtain detailed information of a specific single page.
  • moduleDetail:Used to obtain detailed information of a specific content model.
  • tagDetail:Used to obtain detailed information of a specific tag.

Their general calling format is roughly like this:{% XXXDetail 变量名称 with name="字段名称" token="别名字符串" %}Here,变量名称It is optional, if you want to directly output a field, you can omit it;name="字段名称"Then it specifies the specific content field you want to retrieve, such asTitle/DescriptionorContent; whiletoken="别名字符串"Then it is the star of our day, allowing you to directly lock and extract the corresponding content through that unique URL alias set in the background.

Practical Exercise: MastertokenThe calling skills of auto

To better understandtokenThe practical application of auto, we explore in detail through several common scenarios.

Scenario one: Get the detailed information of a specific article (document) of auto

Imagine that you might need to display a fixed article's title and link in a specific area of the website, such as the "Recommended Reading" module on the homepage. This article's ID might change due to data migration. At this point, if you set a stable URL alias for this article, such asabout-our-company,then it can be accessed bytokencan be easily obtained.

{# 假设“关于我们公司”这篇文章的URL别名是 "about-our-company" #}
<div>
    <h3>关于我们</h3>
    {% archiveDetail companyIntro with name="Description" token="about-our-company" %}
    <p>{{ companyIntro|truncatechars:100 }}</p> {# 截取前100个字符显示简介 #}
    {% archiveDetail companyLink with name="Link" token="about-our-company" %}
    <a href="{{ companyLink }}">了解更多</a>
</div>

Through this code, no matter how the article ID changes, as long as the URL aliasabout-our-companyKeep it unchanged, we can always accurately obtain its introduction and link. This approach greatly enhances the robustness and maintainability of the template code.

Scene two: Get detailed information of a specific category

Sometimes, we may need to permanently display the introduction of a certain product category in the website sidebar or link to a specific solution category in the footer.tokenWe can conveniently achieve this goal.

{# 假设有一个名为“热门产品”的分类,其URL别名是 "hot-products" #}
<div class="sidebar-category">
    <h3>{% categoryDetail with name="Title" token="hot-products" %}</h3>
    <p>{% categoryDetail with name="Description" token="hot-products" %}</p>
    {% categoryDetail hotProductLink with name="Link" token="hot-products" %}
    <a href="{{ hotProductLink }}">查看热门产品</a>
</div>

Even if the category ID changes, as long astokenit remains unchanged, the content of the sidebar will also be updated consistently.

Scenario three: Retrieve the content of a specific single page

Single-page websites are very common in corporate websites, such as "Contact UstokenIt is the most natural choice to call them.

`twig {# 假设“服务条款”单页的URL别名是 “terms-of-service” #}

<nav>
    <ul>
        <li><a href="/">首页</a></li>
        {% pageDetail termsLink with name="Link" token="terms-of-