How to highlight the category link being accessed according to the `item.IsCurrent` field?

Calendar 👁️ 59

As an experienced website operations expert, I know that user experience is the foundation of website success.How to help visitors quickly locate their current position on a content-rich website and clearly understand the navigation structure is the key to improving user satisfaction.item.IsCurrentThe field, cleverly highlighting the current category link being accessed, thus significantly optimizing the website's navigation experience.

Master AnQiCMS: Skillfully useitem.IsCurrentHighlight the current category link to enhance user experience.

In a corporate content management system like AnqiCMS, which is core in Go language and focuses on efficiency and customization, every detail is designed to provide convenience for operators.When we are building the navigation and category list of a website, a common and important requirement is to let users see at a glance which category or page they are currently on.item.IsCurrentfield.

item.IsCurrentIt is a boolean flag that the system intelligently determines whether the current loop item (such as categories, navigation links) matches the page the user is currently visiting during the rendering of Anqi CMS. If it matches,item.IsCurrentThe value will betrueOtherwisefalse.This means that we do not need to write additional complex URL parsing logic, the system has already completed this task for us, and we can easily achieve the highlighting effect by using this symbol in the template.

Achieve highlighting: Practical application of category list and navigation menu

Understooditem.IsCurrentThe principle, next let's see how to apply it in the actual template file. Anqi CMS template syntax is similar to Django, intuitive and easy to understand, very suitable for quick learning.

1. Highlight display of Category List (CategoryList)

In many websites, the sidebar or the top of the page often displays a category list to facilitate user browsing and filtering of content.Assuming we want the currently visited category to be displayed in a list with different styles (for example, bold text or color).categoryListTags anditem.IsCurrentto achieve.

When we usecategoryListEach object will be included when the label loops through the categoryitemwhen the label loops through the categoryIsCurrentThis property. We only need to add a conditional judgment in the HTML element, based onitem.IsCurrentthe value to dynamically apply CSS classes.

{% categoryList categories with moduleId="1" parentId="0" %}
    <ul class="category-list">
        {% for item in categories %}
            <li class="category-item {% if item.IsCurrent %}active{% endif %}">
                <a href="{{ item.Link }}">{{item.Title}}</a>
            </li>
        {% endfor %}
    </ul>
{% endcategoryList %}

In the above code snippet, we assign a class to each<li>Elements are dynamically addedactivethe class. Whenitem.IsCurrentWithtruethen,activethe class will be attached to<li>. Next, we just need to define the styles for the class in the website's CSS stylesheet.activethat are needed:

/* 示例 CSS 样式 */
.category-list .category-item.active a {
    color: #007bff; /* 例如,高亮为蓝色 */
    font-weight: bold; /* 字体加粗 */
    border-left: 3px solid #007bff; /* 左侧添加指示线 */
    padding-left: 10px;
}
/* 其他非高亮样式 */
.category-list .category-item a {
    color: #333;
    text-decoration: none;
    display: block;
    padding: 8px 0;
    transition: all 0.3s ease;
}

This way, when users browse different categories, the link of the current category will be highlighted in a prominent way, greatly enhancing the clarity of navigation.

2. Highlight display of the main navigation menu (Navigation Menu)

The main navigation menu of a website is usually located at the top of the page and is the main entrance for users to access various core pages. Similar to the category list, the highlighting of the main navigation menu can also be achieved throughnavListTags anditem.IsCurrentImplementation, even multi-level navigation can be handled easily.

navListTags support multi-level navigation structure, within theitem.NavListProperties can be used to loop through sub-navigation. When dealing with these items, we can still useitem.IsCurrent.

{% navList navs %}
    <nav class="main-navigation">
        <ul>
            {% for item in navs %}
                <li class="nav-item {% if item.IsCurrent %}active{% endif %}">
                    <a href="{{ item.Link }}">{{item.Title}}</a>
                    {% if item.NavList %}
                        <ul class="sub-navigation">
                            {% for subItem in item.NavList %}
                                <li class="sub-nav-item {% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
    </nav>
{% endnavList %}

The corresponding CSS style can be defined as follows:

/* 主导航高亮样式 */
.main-navigation .nav-item.active > a {
    color: #fff; /* 主导航文字变白 */
    background-color: #007bff; /* 背景变蓝 */
    border-radius: 4px;
}
/* 子导航高亮样式 */
.sub-navigation .sub-nav-item.active a {
    color: #007bff;
    font-weight: bold;
}
/* 其他非高亮样式 */
.main-navigation .nav-item a,
.sub-navigation .sub-nav-item a {
    padding: 10px 15px;
    display: block;
    text-decoration: none;
    color: #333;
}

In this way, whether it is the main navigation or the sub-items in the dropdown menu, the currently accessed link can be highlighted accurately, providing the user with a seamless navigation experience.

Why is it so important?item.IsCurrentThe value it brings

A seemingly simple feature, but it can bring multiple values to the website:

  • Improve user experience:Users do not need to guess and can clearly know their position on the website, reducing confusion and improving browsing efficiency.
  • Enhance navigation clarity:By visual differences, the classification and navigation structure are clear at a glance, helping users quickly understand the layout of the website content.
  • Reduce bounce rate:A clear navigation path can encourage users to explore the website content deeply, thereby possibly increasing the time spent on the page and reducing the likelihood of leaving the website prematurely.
  • Ease of use:The built-in of AnQi CMSitem.IsCurrentGreatly simplified development and maintenance work, operators and developers can focus more on the content itself rather than complex client or server-side logic.

Operation is small.

Related articles

What is the actual use of the `item.Spacer` field in multi-level category display, and how to beautify the prefix?

As an experienced website operations expert, I know that every seemingly minor feature in a content management system may play a key role in user experience and content presentation.Today, let's delve deeply into a frequently overlooked but indispensable field in AnQiCMS, which is essential for building a clear and hierarchical content structure - `item.Spacer`.

2025-11-06

How to display a category thumbnail (`item.Thumb`) or Banner image (`item.Logo`) next to the category list?

As an experienced website operation expert, I am well aware of the importance of the visual presentation of website content in terms of user experience and information delivery.In a powerful and flexible system like AnQiCMS, we have multiple ways to achieve fine-grained content control, especially in key navigation areas like category lists. How to effectively display category thumbnails or Banner images is an important aspect to enhance the professionalism and attractiveness of a website.Today, let us delve into how to cleverly integrate these visual elements into the category list in Anqi CMS.--- ###

2025-11-06

Can the `categoryList` tag display the number of documents under each category? How can `item.ArchiveCount` be retrieved and displayed?

As an experienced website operation expert, I know that how to efficiently and intuitively display content data in a content management system is the key to improving user experience and content operation efficiency.AnQiCMS (AnQiCMS) offers us great flexibility with its simple and efficient architecture.Today, let's delve deeply into a question that both operators and template developers are very concerned about: Can the `categoryList` tag display the number of documents under each category?How to get and display `item.ArchiveCount`?” --- ##

2025-11-06

How can you determine if a category has a subcategory? How can the `item.HasChildren` field be applied to conditional judgments?

As an experienced website operations expert, I deeply understand the importance of efficiently using template tags in the daily application and content strategy formulation of AnQiCMS (AnQiCMS).Today, let's delve deeply into a very practical topic in website structure construction: how to determine whether a category (Category) contains subcategories, and how to cleverly use the `item.HasChildren` field in templates to achieve intelligent content display.

2025-11-06

Can the `categoryList` tag return the `item.Description` field for SEO description on the category page?

In website operation, the SEO description (Meta Description) of the category page is one of the key elements to improve search engine ranking and click-through rate.A well-written description that not only accurately summarizes the page content but also attracts users to click.For website administrators and content operators using AnQiCMS, how to efficiently and accurately utilize the system functions to manage these descriptions is a common issue.Today, let's delve deeply into a specific issue: `categoryList` tag returns the `item'

2025-11-06

How `categoryList` and `archiveList` work together to display the latest few documents under each category?

As an experienced website operations expert, I am well aware of the powerful aspects of a content management system (CMS), not only in terms of its backend functionality, but also in the flexibility of its frontend content display.AnQiCMS (AnQi CMS) is exactly such an outstanding tool, based on the high-performance architecture of the Go language,配合 its concise and efficient template tag system, it allows us to easily handle various complex content display needs. Today

2025-11-06

How to get the category details information of a specified ID through the `categoryList` tag instead of the current page?

As an experienced website operations expert, I know how important it is to flexibly obtain and display data when managing content.Especially when building the AnQiCMS website, we often encounter situations where we need to obtain specific category information rather than the context of the current page.Today, let's delve deeply into how to cleverly use AnQiCMS template tags to accurately obtain the category details you want.How to accurately locate: How to get the category details of a specified ID instead of the current page?In AnQiCMS template development, `categoryList` and

2025-11-06

How to use the "offset,limit" mode in the `limit` parameter supported by `categoryList`, and what scenarios are applicable?

## Masterful Manipulation of Category List: Practical Use of AnQiCMS `categoryList`'s `offset,limit` Pattern As an experienced website operations expert, I am well aware of how important flexible data display capabilities are when building and optimizing website content.AnQiCMS with its concise and efficient features provides us with many powerful template tags, among which the `categoryList` tag is the core tool for managing website classification content. Today

2025-11-06