How to highlight the current page in the `navList` navigation menu based on the `IsCurrent` property?

Calendar 👁️ 57

In a fast-paced digital world, a clear and intuitive website navigation menu is the foundation of a good user experience.As an experienced website operations expert, I am well aware of the powerful capabilities of AnQiCMS (AnQiCMS) in providing efficient and customizable content management solutions.navListLabel collaborationIsCurrentThe property can easily highlight the current page, greatly enhancing the professionalism and user-friendliness of the website.

Today, let's delve into how to skillfully use in AnQiCMSnavListnavigation menu'sIsCurrentAttribute, let your website navigation guide users like a beacon, lighting up their path of access.

Understand AnQiCMS'navListNavigation tags

In AnQiCMS,navListIt is a core template tag that allows us to dynamically retrieve predefined navigation menu data from the background database.These navigation links can be flexibly configured and managed in the AnQiCMS background under “Background Settings” -> “Website Navigation Settings”, supporting multi-level menus and various link types, such as built-in links, category page links, or external links.

UsenavListWhen labeling, the navigation loop usually starts like this:

{% navList navs %}
    {# 导航项在这里遍历 #}
{% endnavList %}

Here, navsThis is the variable name we define for the navigation list, and you can also name it with other more descriptive words according to your habit. Each one in the loopitemWe usually willforNaming in the loop includes a series of useful properties, such asTitle(The display name of navigation),Link(The URL address navigated to), as well asNavListIf the current navigation item has a submenu, this property will contain a sub-navigation list.

These properties共同build theskeleton of the website navigation, but to make the navigation smarter, we still need to introduce a key role -IsCurrent.

IsCurrent: Navigation highlight intelligent indicator light

AnQiCMS provides a very considerate built-in attribute-IsCurrent. This attribute is a boolean value(trueorfalseIt will automatically determine whether the corresponding navigation item is the current page based on the URL the current user is visiting. If the link of the current navigation item matches the URL of the page the user is visiting, thenIsCurrentThe value istrueOtherwisefalse.

Its strength lies in the fact that you do not need to write complex JavaScript code or backend logic to judge the current page, AnQiCMS has already done everything for you. All you need to do is use this property in the template to add a special CSS class to the corresponding navigation item, for exampleactiveThus, highlighting effects can be achieved visually.

Suppose we have a simple single-layer navigation, we can use it in this way.IsCurrentto addactiveClass:

{% navList navs %}
    <ul>
        {% for item in navs %}
            <li class="{% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{ item.Title }}</a>
            </li>
        {% endfor %}
    </ul>
{% endnavList %}

In this code block,{% if item.IsCurrent %}is a conditional judgment, ifitem.IsCurrentWithtruethen, it will output.activeThis class name. In this way, the current page's<li>tag will haveactiveClass.

to deal with multi-level navigation:IsCurrentnested application

Modern websites usually use multi-level navigation to organize content, AnQiCMS'snavListThe tag also perfectly supports this structure. When handling multi-level navigation,IsCurrentThe property also applies to both parent and child navigation items. This means that if a user is visiting a child menu page, not only theIsCurrentwilltrue, but also the corresponding parent navigation item'sIsCurrentIt will also betrueThis can achieve the effect of parent-child menu联动 highlighting, greatly enhancing the user's sense of orientation in complex navigation structures.

Let's look at a real example with two-level navigation:

<nav class="main-nav">
    {% navList navs %}
    <ul>
        {%- for item in navs %}
            <li class="{% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{item.Title}}</a>
                {%- if item.NavList %} {# 检查是否有子导航 #}
                <dl class="sub-menu">
                    {%- for inner in item.NavList %} {# 遍历子导航 #}
                        <dd class="{% if inner.IsCurrent %}active{% endif %}">
                            <a href="{{ inner.Link }}">{{inner.Title}}</a>
                        </dd>
                    {% endfor %}
                </dl>
                {% endif %}
            </li>
        {% endfor %}
    </ul>
    {% endnavList %}
</nav>

In this example, we applied the main navigation and sub-navigation both.IsCurrentDetermine. Whether it is a main navigation item or a sub-navigation item, as long as it is the current page, it will be givenactiveclass.This way, when the user enters the 'Product Details' page, not only will the sub-menu item 'Product Details' be highlighted, but the parent main menu item 'Product Center' will also be highlighted, allowing the user to immediately understand their location.

The final embellishment: using CSS to achieve visual highlighting

Just addactiveThe class name is not enough to achieve visual highlighting, we still need to cooperate with CSS style rules to define the specific effects of highlighting. You can design it according to the style of the website.activeAdd different colors, backgrounds, font weights, or underlines and other styles.

Here are some basic CSS examples that you can add to your website's style file (usuallypublic/static/css/style.cssOr you can use your custom CSS file:

/* 主导航高亮样式 */
.main-nav ul li.active > a {
    color: #007bff; /* 例如,蓝色文字 */
    font-weight: bold; /* 字体加粗 */
    border-bottom: 2px solid #007bff; /* 底部边框 */
}

/* 子导航高亮样式 */
.main-nav .sub-menu dd.active a {
    background-color: #f0f0f0; /* 浅灰色背景 */
    color: #333; /* 文字颜色 */
    font-weight: 600; /* 略微加粗 */
}

/* 鼠标悬停效果,保持与高亮一致性 */
.main-nav ul li a:hover,
.main-nav .sub-menu dd a:hover {
    color: #0056b3; /* 鼠标悬停时颜色变深 */
    text-decoration: none;
}

By following these steps, you can use them in AnQiCMSnavListTags andIsCurrentThe attribute, combined with simple CSS styles, can easily achieve the highlighting of the current page in the navigation menu, thereby providing your website visitors with a clearer, more friendly browsing experience.This automation and flexibility mechanism is exactly the embodiment of the


Frequently Asked Questions (FAQ)

  1. IsCurrentHow does the property determine the current page? IsCurrentThe property is automatically calculated and injected by the AnQiCMS backend logic when rendering templates.It will match the current request URL path with the links of each navigation item in the background navigation settings.IsCurrentThe properties will be set totrueThis process does not require front-end intervention, it is all efficiently handled internally by AnQiCMS.

  2. Did I modify the navigation link in the background, will the highlighted display on the front end update immediately?In most cases

Related articles

How to judge whether a contact field (such as Qrcode) in the AnQiCMS template has a value?

In website operation and template development, we often need to dynamically adjust the display of the front-end page based on the setting of the background content.Especially for important information such as contact information, ensure that it is displayed after it exists, which can effectively avoid broken links, blank areas, or incomplete information on the page, thereby improving the user experience.Today, let's delve into how to elegantly and accurately determine whether a contact field (such as `Qrcode`) obtained by the `contact` tag in the AnQiCMS template has been set.

2025-11-06

How to judge whether the website is closed and display a prompt based on the `SiteCloseTips` of the system settings (`{% system %}`)?

As an experienced website operations expert, I know that the stable operation of the website is of great importance, but sometimes, due to reasons such as maintenance, upgrades, or data migration, the website has to temporarily shut its doors.How to communicate with visitors elegantly during a closure period, ensuring user experience while effectively managing expectations, is a detail that every operator needs to pay attention to.AnQiCMS (AnQiCMS) provides a flexible mechanism in this regard, allowing us to deal with it easily.Today, let's delve deeply into how to set up tags in Anqi CMS through system settings `{% system

2025-11-06

How to determine if there is a previous or next document on the document detail page and display navigation links?

As an experienced website operations expert, I know that a smooth reading experience is crucial when users browse content.A good document detail page should not only display the core content but also guide users to the next step, such as reading related content or easily switching to the previous or next page.This not only increases the user's stay time on the website and reduces the bounce rate, but it is also SEO-friendly, helping search engines to better crawl and understand the website structure.In AnQiCMS (AnQiCMS), implement the previous and next navigation links on the document detail page

2025-11-06

In AnQiCMS template, how to determine if a certain `flag` attribute (such as `recommended` or `headline`) is set?

As an experienced website operations expert, I am well aware in my daily work that the flexibility of content display is crucial for user experience and operational efficiency.AnQiCMS (AnQi Content Management System) is the choice of many enterprises and operators due to its powerful customizability and simple and efficient template engine.Today, let's delve into a very practical skill in AnQiCMS template making: how to determine if the specific `flag` attribute (such as "Recommended" or "Top") of a document is set, and adjust the content display accordingly.

2025-11-06

How to determine if the `navList` menu item has child navigation (`item.NavList`) and perform nested rendering?

## AnQi CMS navigation menu: skillfully use `navList` to implement multi-level nesting and child navigation judgment As an experienced website operations expert, I fully understand the importance of a clear and flexible navigation system for user experience and the overall architecture of the website.In AnQiCMS (AnQiCMS), the `navList` tag is the core tool we use to build a powerful navigation system.

2025-11-06

How to determine if the `linkList` friendship link tag list is empty to avoid displaying an empty tag?

As an experienced website operations expert, I have accumulated rich experience in content management and template optimization in AnQiCMS.I know well that a smooth, beautiful and quick-loading website cannot be separated from the meticulous refinement of every detail.Today, let's delve deeply into an issue that is often overlooked in template development but is crucial for user experience and page neatness: how to avoid displaying redundant empty tags when the `linkList` friendship link tag list is empty.Avoid displaying empty tags: AnQi CMS

2025-11-06

How to conditionally output the standard link according to the `CanonicalUrl` tag in AnQiCMS templates?

Hello! As an experienced website operations expert, I fully understand that in daily work, we not only need to pay attention to the quality of the website content, but also to the impact of technical details on SEO.The canonical URL is one of the crucial details that can effectively solve the problem of duplicate website content, concentrate page authority, and thus improve search engine rankings.Today, let's delve deeply into how to intelligently and elegantly output standard links based on the existence or absence of the `CanonicalUrl` field within the `tdk` tag in AnQiCMS templates

2025-11-06

In the `pagination` tag, how to determine if the current page is the first or last page to control the style?

As an experienced website operations expert, I know the importance of a powerful and flexible content management system for the success of a website.AnQiCMS leverages the efficiency of the Go language and its deep consideration for content operation, providing us with many conveniences.Today, let's delve into the wonderful use of the `pagination` tag in AnQiCMS, especially how to accurately judge whether the current page is the first page or the last page, thereby flexibly controlling the style to create a smoother and more intuitive navigation experience for users.

2025-11-06