How to get the default category ID of the current content model through the `moduleDetail` tag, so as to build category navigation in the template?

Calendar 👁️ 73

Hello! As an experienced website operations expert, I am very happy to share with you how to use the template in AnQiCMS (AnQiCMS) by cleverly utilizingmoduleDetailTag to retrieve the current content model ID and build a dynamic and accurate classification navigation based on it.AnQi CMS provides us content operators with great convenience with its efficient and flexible content model, and a deep understanding of its template tags is the key to bringing these advantages into play.


Enterprise CMS Template Development实战:Skillful UsemoduleDetailGet the current content model ID, build an intelligent classification navigation

In a content management system, clear and intuitive category navigation is the core of user experience, as well as the foundation of content organization and SEO optimization.AnQi CMS, with its high-performance architecture based on the Go language and flexible content model design, provides a solid foundation for us to build various websites.When faced with a website that has multiple content models (such as articles, products, cases, etc.), how to make the navigation bar intelligently display its exclusive categories according to the current page's content model has become a common template development requirement.moduleDetailThe place where tags can fully show their talents.

Insight into AnQi CMS content model: Everything starts with structure

In AnQi CMS, the content model (Content Model) plays the role of the content skeleton.It allows us to define unique fields and structures for different types of content.For example, you may have an "article modelEach category belongs to a specific content model, which means a 'news category' will belong to the 'article model', and a 'phone category' will belong to the 'product model'.Understanding this hierarchical relationship is the first step in building intelligent navigation.

moduleDetailTag: Get the 'ID number' of the current content model

In order to build a classification navigation that matches the current content model, we first need to know which content model the current page is located in. At this time,moduleDetailThe label comes in handy. Its main function is to obtain the detailed information of the content model, including the model ID, title, link, table name, etc.

In the template,moduleDetailTags usually automatically identify the content model of the current page. We most commonly use itsIdfield, which is equivalent to the unique 'ID card number' of the content model.

For example, when you are on an article detail page or an article list page, no additional specification is requiredidortokenparameter,moduleDetailit can automatically obtain information about the current model. We can retrieve the ID of the current content model in this way:

{# 假设我们想获取当前内容模型的ID #}
{% moduleDetail currentModuleId with name="Id" %}

In this concise code,currentModuleIdThis variable will store the numeric ID of the current content model. This ID is the key to connecting the content model with the category list.

From Model ID to Category Navigation: Actual Operation Steps

Obtained the ID of the current content model (i.e.currentModuleIdAfter that, we can use it as a bridge to call the category list associated with the model. Anqi CMS providescategoryListLabel, used specifically to retrieve category data. This label has a very important parametermoduleIdIt allows us to specify which content model's categories we want to retrieve.

At the same time, in order to build the top-level category navigation, we usually want to only display the top-level (first-level) categories without any parent categories.categoryListlabel'sparentId="0"The parameters can help us achieve this goal.

Below, let's build a code example to dynamically display a category navigation based on the current content model:

<nav class="category-navigation">
    <ul>
        {# 首先,获取当前页面的内容模型ID #}
        {% moduleDetail currentModuleId with name="Id" %}

        {# 接着,使用这个模型ID和parentId="0"来获取该模型下的所有顶级分类 #}
        {% categoryList categories with moduleId=currentModuleId parentId="0" %}
            {% for item in categories %}
            <li {% if item.IsCurrent %}class="active"{% endif %}>
                <a href="{{ item.Link }}" title="{{ item.Title }}">
                    {{ item.Title }}
                </a>
                {# 如果需要展示二级分类,可以在这里嵌套另一个categoryList标签 #}
                {% if item.HasChildren %}
                    <ul class="sub-categories">
                        {% categoryList subCategories with parentId=item.Id %}
                            {% for subItem in subCategories %}
                            <li {% if subItem.IsCurrent %}class="active"{% endif %}>
                                <a href="{{ subItem.Link }}" title="{{ subItem.Title }}">
                                    {{ subItem.Title }}
                                </a>
                            </li>
                            {% endfor %}
                        {% endcategoryList %}
                    </ul>
                {% endif %}
            </li>
            {% empty %}
            {# 如果当前模型下没有顶级分类,则显示提示信息 #}
            <li>当前模型暂无可用分类。</li>
            {% endfor %}
        {% endcategoryList %}
    </ul>
</nav>

In this code, we first usemoduleDetailSet the current content model toIdAssign tocurrentModuleIdThen, incategoryListIn the tag, we setmoduleId=currentModuleIdTo limit the scope of the categories, and throughparentId="0"Make sure to only retrieve the top-level categories.forLoop through these categories,item.Linkanditem.TitleUsed separately to generate category links and display names.

To enhance user experience, we also utilizeditem.IsCurrentProperty. When a category is the category of the current page,IsCurrentwill returntruewe can addactivea class name to highlight it. In addition, by judgingitem.HasChildrenwe can further nest.categoryListTags to display multi-level classification, making navigation more flexible and complete.{% empty %}Tags elegantly handle the display situation when there are no categories under a certain content model.

Optimize and advance: Details for improving user experience

Building dynamic navigation is not just about technical implementation, but also about focusing on user experience. In addition to the aforementioned basic functions, you can also consider:

  • Display multi-level classification:As shown in the example, usingitem.HasChildrenproperties配合nestedcategoryListtags, you can easily achieve two-level or even multi-level dropdown menus or sidebar navigation for classification.
  • Breadcrumbs navigation:CombinebreadcrumbTags, provide clear path guidance for users, and improve the ease of use of the website.
  • Caching strategy:For category data that does not change frequently, consider caching at an appropriate level to reduce database queries and improve page loading speed.

In this way, no matter which article page or product page your users visit, the navigation bar can intelligently adjust, only displaying categories related to the current content model, greatly enhancing the website's intelligence and user-friendliness.

Summary

Of Security CMSmoduleDetailLabels may seem simple, but they are the key starting point for building dynamic, intelligent classification navigation. By obtaining the ID of the current content model and passing it as a parameter tocategoryListLabel, we can easily achieve adaptive classification navigation, thereby providing users with more accurate and smooth browsing experience.This modular, tagged development approach is exactly the strength of Anqi CMS as an enterprise-level content management system.


Frequently Asked Questions (FAQ)

  1. Does the AnQi CMS content model have a 'default category ID' configuration item?The AnQi CMS content model does not have a 'default category ID'.

Related articles

Why must the `model table name` of the content model be in English lowercase letters? What is the relationship with the underlying Go language development of Anqi CMS?

AnQi CMS, as an enterprise-level content management system meticulously crafted based on the Go language, has always adhered to a rigorous design philosophy on the path of pursuing ultimate performance, stability, reliability, and flexibility.Today, let's delve into a seemingly simple yet deeply technical consideration: why must the table name of the content model be in lowercase English letters?How closely is this related to the underlying development of the Go language?### The foundation of AnQi CMS: Go language and efficient design Firstly

2025-11-07

Does the `moduleDetail` tag provide fields to retrieve the model creation time or update time to achieve more refined template display?

As an experienced website operations expert, I fully understand that the precise control and display of time dimension information in content management systems is crucial for website operations and user experience.Whether it is the publication time of the article or the last update time of the content, it can convey important information to the reader and also have a positive impact on search engine optimization (SEO).

2025-11-07

How to dynamically judge whether a custom field of a content model is set as required in the template?

Anqi CMS is an efficient and flexible content management system, its powerful content model customization function indeed brings great convenience to enterprises and operators.In daily content operation, we often add various custom fields for different content models (such as articles, products, events, etc.) according to business needs.These fields are some optional, some are required to be filled in, that is, 'mandatory items'.

2025-11-07

Can I define different types of 'recommendation attributes' for different content models (such as 'top news' for article models and 'new product' for product models)?

As an experienced website operations expert, I know that accurately recommending different types of content in content management is the key to improving user experience and operational efficiency.AnQi CMS, with its flexible content model design, indeed provides us with powerful content organization capabilities.And regarding the differentiated definition of 'recommended attributes', this embodies some exquisite operational strategies and technical implementation methods, which are worthy of in-depth exploration.### AnQi CMS: The Flexible Application of Content Model and "Recommended Attributes" Many operators will have a question when they first contact AnQi CMS

2025-11-07

If I want to restrict certain user groups to only edit specific content models, how can I configure this in the backend, and what is the association with the `moduleDetail` tag?

As an experienced website operations expert, I deeply understand the importance of fine-grained permission management in content operations.An excellent content management system that not only supports a variety of content formats but also provides flexible permission control, ensuring that each team member can work efficiently within their scope of responsibilities while avoiding misoperations and potential security risks.AnQiCMS (AnQiCMS) performs well in this regard, with its powerful user group management and flexible content model mechanism, which is the key to achieving this goal.

2025-11-07

The `moduleDetail` tag returns the `Keywords` field, is it a single keyword or a comma-separated string? How should it be correctly parsed in the template?

## Deeply analyze the `Keywords` field of the `moduleDetail` tag in AnQiCMS: Keyword format and template parsing techniques As an experienced website operations expert, I know that how to efficiently and flexibly handle and display content in a content management system is the key to success.AnQiCMS (AnQiCMS) provides us with great convenience with its concise and efficient architecture.Today, let's delve into a specific problem that often occurs in template making

2025-11-07

How to dynamically build a link to the home page or list page of the model based on the content model ID in the front-end template?

## The wisdom of dynamically building jump links in the Anqi CMS front-end template based on content model ID As an experienced website operations expert, I know that flexibility and automation are the key to improving efficiency in daily content management.The AnQi CMS provides us with great convenience with its powerful content model customization capabilities and friendly template engine.Today, let's delve into a very practical skill in front-end development: how to dynamically build a link to the home page or list page of the model based on the content model ID without hardcoding the path

2025-11-07

`changelog` mentions that articles and products are generated according to the model, what is the core impact on template creation after upgrading to the old version?

As an experienced website operations expert, I know that the core value of the Content Management System (CMS) lies in its flexibility and scalability.The continuous evolution of AnQiCMS (AnQiCMS) in content management, especially the adjustment of content generation logic in version updates, is a key point worthy of in-depth exploration for us operators and template developers.Today, let's talk about the change mentioned in the `changelog` of Anqi CMS where 'articles and products are generated by models', and what core impacts it brings to the template creation after upgrading to the old version

2025-11-07