How to display the current model name or URL alias in AnQiCMS?

Calendar 👁️ 56

In website content management, we often need to make the various parts of the website smartly adapt and display information. One common requirement is how to dynamically display the current content model name or its URL alias on the front-end page.This is crucial for enhancing user experience, optimizing search engine performance, and flexible website structure management.AnQiCMS is a system focused on enterprise-level content management, providing very flexible and powerful template tag functions, making it intuitive and efficient to achieve this goal.

Understanding AnQiCMS content model and URL alias mechanism

One of AnQiCMS's core advantages lies in its 'flexible content model'.This means that we can not only use the built-in 'article' and 'product' models, but also customize various content types according to actual business needs.Each content model has its own name (such as "news", "case") and a unique "model table name" (usually as part of the URL alias).

URL alias, mainly reflected in the pseudo-static rule configuration of AnQiCMS. Through the pseudo-static rule, we can customize the link structure of the website content, such as/{module}-{id}.htmlor/{module}/list-{catname}.html. Here,{module}It refers to the URL alias of the current content model, usually corresponding to the model's table name in the system.The purpose of doing this is to make the URL more friendly and readable, as well as beneficial for search engine crawling and ranking (SEO).

Therefore, to display the name or URL alias of the current model, we need to use the template tags provided by AnQiCMS to extract information from these core configurations.

How to display the current model's name in the template?

When we access a model's homepage (such as/article) or model list page (such as/article/list-1.htmlWhen, sometimes, you may want to display the current model's name on the page, such as "Article List", "Product Center", etc. AnQiCMS providesmoduleDetailThe tag is used specifically to obtain detailed information about the content model.

To display the name of the current model, we can usemoduleDetaillabel and specifyname="Title". For example:

{% moduleDetail with name="Title" %}

This tag will intelligently obtain the name of the model belonging to the current page and output it directly. If we need to assign the model name to a variable for multiple uses in the template or other logical judgments, we can do it like this:

{% moduleDetail currentModuleName with name="Title" %}
<h1>{{ currentModuleName }}</h1>

Application scenario:

  • Model homepage title:Display "XX Center" or "XX List" at the top of the model list page.
  • Breadcrumbs navigation:In the multi-level breadcrumb, the model level can dynamically display its name.
  • Conditional rendering:Load different CSS styles or JavaScript scripts based on the model name.

How to display the current model's URL alias in the template?

Display the model's URL alias, which is usually referred to in pseudo-static rules usage{module}Placeholder model identifier. In AnQiCMS, this identifier is the model's 'model table name'. Similarly,moduleDetailtags can also help us obtain it.

To display the current model's URL alias (i.e., the table name of the model), we can usemoduleDetaillabel and specifyname="TableName". For example:

{% moduleDetail with name="TableName" %}

Similarly, it can also be assigned to a variable:

{% moduleDetail currentModuleAlias with name="TableName" %}
<p>当前模型的URL别名为:{{ currentModuleAlias }}</p>

In addition, if our requirement is to obtainThe complete URL link of the current model pageInstead of just its alias identifier, you can usename="Link":

<p>访问当前模型首页:<a href="{% moduleDetail with name="Link" %}">点击这里</a></p>

Application scenario:

  • Dynamically generate a link:When it is necessary to jump to other sub-pages of the current model, a URL can be dynamically constructed.
  • Advanced template logic:If the need arises to make special backend data requests or frontend routing handling based on the model's URL alias, this information is very useful.
  • SEO optimization:Ensure that the internal link structure on the page is consistent with the pseudo-static rules, enhancing SEO effects.

Practical scenarios and techniques

Combining these tags can build a highly dynamic and maintainable website.

  1. Dynamic breadcrumb navigation:AnQiCMS providesbreadcrumbThe tag automatically generates breadcrumbs, it intelligently identifies the model, category, document, and other levels of the current page and displays their names.Through this tag, you do not need to manually write complex logic.

  2. Mapping of content model ID and name:On the document detail page or category list page, we may need to know the model ID of the current document or category, and then use this ID to obtain the name or alias of the model. For example,archiveDetailorcategoryDetailIn the tag, you can getModuleIdfield.

    {% archiveDetail currentArchive with name="Id" %}
    {% archiveDetail currentModuleId with name="ModuleId" %}
    <p>当前文章ID: {{ currentArchive }},所属模型ID: {{ currentModuleId }}</p>
    {% moduleDetail moduleNameForArchive with name="Title" id=currentModuleId %}
    <p>所属模型名称: {{ moduleNameForArchive }}</p>
    
  3. Load specific content based on model alias:If your template needs to display different sidebar content or ad slots based on different models, you can use the model's URL alias for conditional judgment:

    {% moduleDetail currentModuleAlias with name="TableName" %}
    {% if currentModuleAlias == "article" %}
        {# 加载文章模型专属侧边栏 #}
        {% include "partial/article_sidebar.html" %}
    {% elif currentModuleAlias == "product" %}
        {# 加载产品模型专属侧边栏 #}
        {% include "partial/product_sidebar.html" %}
    {% else %}
        {# 默认侧边栏 #}
        {% include "partial/default_sidebar.html" %}
    {% endif %}
    

By using these powerful and flexible template tags of AnQiCMS, we can easily display the current model's name and its URL alias on the website front-end, thereby building a smarter and more expressive website.This simplifies the development process and lays a solid foundation for the long-term operation and SEO optimization of the website.


Frequently Asked Questions (FAQ)

1.moduleDetailCan the tag be used on all page types? moduleDetailTags are usually used to retrieve the model information most relevant to the current page context.It is most suitable on pages directly associated with the model, such as the model homepage and list page.On the document details page or category details page, you can first obtain the document or category'sModuleIduse first, and then usemoduleDetailLabel combinationidParameters to query information about a specific model.

2. Are the 'URL alias' and 'model table name' the same concept in AnQiCMS?In the pseudo-static rules of AnQiCMS, {module}Placeholders typically directly correspond to the model's 'model table name'.In the background "Content Model Usage Help","URL alias" field is used to set this "model table name".Therefore, at the template level, you can pass throughmoduleDetailTag

Related articles

How to remove HTML tags in AnQiCMS template and display only plain text content?

When using AnQiCMS for content creation and display, we often need to flexibly control the presentation of content on the front end.Sometimes, the article or product description may contain rich HTML tags, which are used to provide beautiful layout on the detail page.

2025-11-07

How to automatically add watermarks to images in article content in AnQiCMS to protect copyright?

In today's era of increasingly rich digital content, the copyright protection of original images is particularly important.Whether it is a carefully photographed product image or an illustration drawn for an article, they all embody the creator's efforts and the brand image of the website.However, the situation where pictures are downloaded and used without permission is common, which not only violates copyright but may also dilute brand influence.Luckyly, AnQiCMS provides a convenient and efficient solution that helps us automatically add watermarks to images on the website, thereby effectively protecting original content.

2025-11-07

How to format numbers in AnQiCMS templates, such as retaining decimal places?

In AnQiCMS template development, formatting numbers for display, especially controlling decimal places, is a very common requirement.No matter whether you want to display the price of products, the percentage in statistical data, or other values that need to be presented accurately, AnQiCMS's powerful template engine provides flexible filters (filters) to help you achieve these goals.

2025-11-07

How to implement custom template file calling for category or article detail pages in AnQiCMS?

During the process of building a website with AnQiCMS, we often encounter such needs: we hope that a certain category list page or a unique article detail page has a layout and style that is different from the global unified default template.AnQiCMS is a content management system focused on flexibility and customization, providing a very convenient and powerful solution in this regard, allowing us to easily implement this fine-grained template calling.Implement custom template calling for category or article detail pages, AnQiCMS mainly provides two main methods

2025-11-07

How to display the list of internal titles (H1, H2, etc.) of the article content on the article detail page?

In Anqi CMS, in order to enhance the reading experience of long articles and the page SEO effect, we usually hope to display a list of internal titles (H1, H2, etc.) on the side or above the article content on the article detail page, which is what we usually call the article catalog or navigation.This makes it convenient for readers to quickly jump to the chapters of interest, and also helps search engines better understand the structure of the article. The AnQi CMS provides a very convenient way to implement this feature, the core lies in its powerful template tags and content field extraction capabilities.###

2025-11-07

How to implement keyword batch replacement in AnQiCMS and affect the display of front-end content?

It is crucial to maintain the accuracy, timeliness, and brand consistency of content in website operations.Especially when the amount of website content is large, if you need to make global changes to specific keywords or phrases, manual operation will be a huge project that is time-consuming and labor-intensive.AnQiCMS (AnQi CMS) exactly discerned this need, providing a powerful feature named 'Full Website Content Replacement' to help users efficiently manage and update website content, thereby affecting the display effect of front-end content.Why do we need to batch replace keywords? With the development of the enterprise, product updates, or market strategy adjustments

2025-11-07

How to ensure that custom parameters set in the AnQiCMS backend can be displayed in the front-end template?

The AnQi CMS endows content management with high flexibility, among which the customizable parameter function is the key to meeting the needs of personalized content display.How to accurately display the unique parameters set for content models such as articles, products, or categories on the website front-end template is a concern for many users.This article will detail this process, helping you fully utilize the powerful customization capabilities of Anqi CMS.

2025-11-07

How to convert a timestamp to a specified date format and display it in the AnQiCMS template?

In Anqi CMS template design, we often encounter the need to display timestamp data in a human-readable date format.Whether it is the publication time of the article, the update date of the content, or the record of user activities, this data is usually stored in the database in the form of timestamps.It is particularly important to master how to convert timestamps to the specified date format in templates so that website visitors can clearly and intuitively understand this information.

2025-11-07