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

Understanding the content model and URL alias mechanism of AnQiCMS

One of the core strengths of AnQiCMS 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

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

Therefore, to display the current model's name or URL alias, 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 are accessing the homepage of a model (such as/article) or the model list page (such as/article/list-1.html)When necessary, one might want to display the current model's name on the page, such as "Article ListmoduleDetailLabel, specifically used to retrieve the details of the content model.

To display the name of the current model, we can usemoduleDetaila tag to specifyname="Title". For example:

{% moduleDetail with name="Title" %}

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

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

Application scenario:

  • Model home page 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:The CSS style or JavaScript script to be loaded varies according to the model name.

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

Display the URL alias of the model, which we usually refer to as the pseudo-static rule usage{module}The 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 URL alias of the current model (i.e., the table name of the model), we can usemoduleDetaila tag to 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 getThe 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 generated link:When it is necessary to jump to other child 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 will be very useful.
  • [en] SEO Optimization:Ensure that the internal link structure on the page is consistent with the pseudo-static rules to enhance SEO effectiveness.

Practical scenarios and skills

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

  1. Dynamic breadcrumb navigation:AnQiCMS providesbreadcrumbThe label is automatically generated to create breadcrumbs, which intelligently identifies the current page's model, category, document hierarchy, and displays its name.With this tag, you do not need to manually write complex logic.

  2. Content model ID and name mapping:In 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 get the model name or alias. For example,archiveDetailorcategoryDetailLabel within, can be accessedModuleIdfield.

    {% 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 %}
    

Through 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, thus building a more intelligent and expressive website.This not only simplifies the development process, but also lays a solid foundation for the long-term operation of the website and SEO optimization.


Common Questions (FAQ)

1.moduleDetailCan the label be used on all page types? moduleDetailTags are usually used to obtain the model information most relevant to the current page context.It is most suitable on the model homepage, list page, and other pages directly associated with the model.ModuleId, and then use moduleDetailTag combinationidUse parameters to query information about a specific model.

2. Does the 'URL alias' and 'model table name' of the model in AnQiCMS refer to the same concept?In the pseudo-static rules of AnQiCMS,{module}Placeholders usually directly correspond to the model's 'model table name'.In the background “Content Model Usage Help”, the “URL Alias” field is used to set this “Model Table Name”.moduleDetailtags