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.
Dynamic breadcrumb navigation:AnQiCMS provides
breadcrumbThe 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.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>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