How to use the `navList` tag to create and display multi-level navigation menus to optimize user browsing?

Calendar 👁️ 70

In website operation, a clear and intuitive navigation system is a key factor in improving user experience, guiding users to explore content, and even optimizing search engine rankings.A well-designed multi-level navigation menu can help visitors quickly find the information they need, reduce the bounce rate, and effectively enhance the in-depth access to website content.In AnqiCMS,navListThe label is the core tool to achieve this goal, allowing us to flexibly build and display hierarchical navigation menus, thereby optimizing the user's browsing path.

UnderstandingnavListLabel: AnqiCMS navigation core

AnqiCMS provides great flexibility to content creators and operators, making the navigation of the website no longer rigid fixed code. ThroughnavListLabel, we can easily retrieve predefined navigation data from the backend and present it in a multi-level structure in the front-end template.This means that updating and adjusting the website menu can be completed with simple operations in the background, without manually modifying the code, which greatly improves the efficiency of content operations.

navListThe power of tags lies in their ability to intelligently recognize and handle the hierarchical relationship of navigation items, and provide information such as the current page status (for example, the currently visited menu item will be highlighted), which are important foundations for building a friendly user interface.

Backend configuration: the cornerstone of building navigation

In usingnavListBefore the label, we need to complete the construction of the navigation menu in the AnqiCMS background. This is the source of the front-end display effect, and it is also to ensurenavListthe premise of normal operation.

  1. Navigation Category Management: Imagine that your website may have multiple areas such as main navigation, footer navigation, sidebar navigation, etc. that need to display different menus.AnqiCMS allows you to create different navigation categories, such as top main navigation, bottom friend links, and so on.You can add or edit these categories by navigating to the "Backend Settings" -> "Navigation Settings" in the backend, through "Navigation Category Management".Each category has a uniquetypeIdThis ID will be used in the template to specify which navigation group to call. By default, the system will provide a 'default navigation' category.

  2. Navigation link settingsOnce the navigation category is determined, we can add specific navigation links to it. Under each navigation category, you can:

    • display nameThis is the text displayed for the navigation item on the website.
    • Parent navigationThis is the key to implementing multi-level navigation. You can choose to set a link as a 'top-level navigation' to make it a first-level menu;You can also choose an existing first-level menu as its 'parent navigation' to create a second-level menu.AnqiCMS supports navigation links up to two levels, which is sufficient and practical for most website structures.
    • Link Type:AnqiCMS provides flexible link options including:
      • Built-in link:For example, the home page, article model home page, product model home page, etc., for quick links to the core pages of the website.
      • Category page link:Directly select the article or product category you have created as navigation, making it convenient for users to directly enter a specific content category.
      • External link: Allows you to add any internal or external URL, providing great flexibility.
    • Subheading nameandNavigation descriptionThese fields can provide additional context for navigation items, although they may not be directly displayed in all designs. However, in some complex layouts or scenarios that require more auxiliary instructions, they can be very useful.
    • Display orderBy adjusting the size of the number, you can control the order of navigation items, with smaller numbers appearing earlier.

By carefully designing the navigation structure in the background, we can provide the front end withnavListThe tag call has prepared all the data.

Template application:navListPractical application of

After the background menu structure is clear, you can use it in the template file.navListThe tag presents it.navListThe usage of tags is intuitive and easy to understand, following the unified syntax of the AnqiCMS template engine.

We usually place the navigation code in the public header of the website (for examplebash.htmlorheader.html),so that it can be reused on all pages.

This is a typicalnavListTag code example, showing how to create a two-level navigation menu:

{# 使用 navList 标签获取后台配置的导航数据,并将其赋值给 'navs' 变量 #}
{% navList navs with typeId=1 %} {# 这里的 typeId=1 假设是主导航的类别ID #}
<ul>
    {# 循环遍历所有一级导航项 #}
    {%- for item in navs %}
        {# 根据 'IsCurrent' 属性判断当前导航项是否为当前页面,并添加 'active' 类名进行高亮 #}
        <li class="{% if item.IsCurrent %}active{% endif %}">
            <a href="{{ item.Link }}">{{item.Title}}</a>

            {# 检查当前一级导航项是否有子导航(二级菜单) #}
            {%- if item.NavList %}
            <dl> {# 使用 <dl>、<ul> 或其他合适的 HTML 标签来包裹子导航 #}
                {# 循环遍历所有二级导航项 #}
                {%- for inner in item.NavList %}
                    {# 同样根据 'IsCurrent' 属性判断并高亮子导航项 #}
                    <dd class="{% if inner.IsCurrent %}active{% endif %}">
                        <a href="{{ inner.Link }}">{{inner.Title}}</a>
                    </dd>
                {% endfor %}
            </dl>
            {% endif %}
        </li>
    {% endfor %}
</ul>
{% endnavList %}

Code analysis:

  • {% navList navs with typeId=1 %}This isnavListThe start of the tag, it will fetch from the background.typeIdAll menu data under the navigation category 1, and store this data in a namednavsin the array variable.
  • {%- for item in navs %}We useforLoop throughnavsEach navigation item in the array.itemRepresents the first-level navigation item being processed. Note-The symbol can remove the empty lines occupied by the tag, making the generated HTML cleaner.
  • {{ item.Link }}and{{item.Title}}: Outputs the link address and display name of the current navigation item.
  • {% if item.IsCurrent %}active{% endif %}This is a very practical feature.item.IsCurrentIt is a boolean value, if the current page is the page pointed to by the navigation item, it will betrueWe can use this feature to add a class for the currently active navigation itemactivecombined with CSS styles to achieve a highlight effect and enhance the user's sense of direction.
  • {%- if item.NavList %}:item.NavListThis is an array that contains all the sub-navigation items of the current top-level navigation item (second-level menu).We only render the HTML structure of the secondary menu when there is a child navigation.
  • {%- for inner in item.NavList %}: Nested.forUsed to iterate over each sub-navigation item in the secondary menu,innerRepresents the current secondary navigation item being processed. ItsLink/TitleandIsCurrentproperties are similar to those of the primary navigation item.

Optimize browsing experience:navListAdvanced techniques

It's not enough to just display multi-level menus, AnqiCMS'snavListIt can also help us further optimize the user's browsing experience:

  1. Dynamic content linkageIn some scenarios, you may want the navigation menu to not only display fixed links but also dynamically display some popular articles or products.For example, when the user hovers over a category menu, in addition to displaying subcategories, it can also display the latest or recommended articles under that category.

    `twig {# Example: Display subcategories under a top-level navigation and show popular articles under each subcategory #}

Related articles

How to display the `tagList` and `tagDataList` tags showing the website tags and related document list?

In website operation, a tag (Tag) is an extremely useful content organization tool.They can not only help users find the content they are interested in faster, improve the user experience of the website, but also optimize the search engine's crawling and understanding of the website content, and have a positive effect on SEO performance.The AnQi CMS provides website administrators with a powerful and flexible tag management feature, through the `tagList` and `tagDataList` template tags, we can easily display tag lists and documents related to specific tags on the website.###

2025-11-08

How do the `pageList` and `pageDetail` tags manage and display the single-page content of a website?

In website operation, single-page content (such as "About Us", "Contact Information", "Service Introduction", etc.) plays a crucial role.They are usually carriers that display the core information of a company, brand story, or specific service details.To efficiently manage and display these pages, AnQiCMS provides the `pageList` and `pageDetail` two core tags, making content organization and presentation both flexible and convenient.### Back-end management of single-page content In AnQiCMS back-end

2025-11-08

How to use `categoryList` and `categoryDetail` tags to build and display category navigation and details?

In website content management, category navigation and detail pages are the core paths for users to browse the website and obtain information, as well as an important basis for search engines to understand the website structure.A clear and intuitive classification system not only greatly enhances the user experience, but also effectively helps the website's SEO performance.For users of Anqi CMS, flexibly using the `categoryList` and `categoryDetail` template tags provided by the system can easily build powerful, beautiful, and practical classification navigation and detail display.--- ### One

2025-11-08

How is the `archiveDetail` tag used to retrieve and display detailed content information for a single document?

In AnQi CMS, the `archiveDetail` tag is a very core and practical tool for template creation, mainly used to retrieve and display detailed content information of a single document.Whether it is a blog post, product details, news report, or any other page content that needs to be independently displayed, `archiveDetail` can help you flexibly extract and present it on the website's front-end page.### `archiveDetail` Tag Core Function Overview The purpose of this tag is to provide rich data support for a single document

2025-11-08

How to automatically generate and display the `breadcrumb` tag showing the user's current location in the breadcrumb navigation?

During website browsing, you may often see a line of text links at the top of the page or above the content area, like breadcrumbs, indicating your current position in the website and the path to get here.This is what we commonly call 'Breadcrumb Navigation'.It can not only help users quickly understand their hierarchical structure on the website, avoid getting lost, but also improve the usability of the website and play a positive role in search engine optimization (SEO).For AnQiCMS users, implementing such a feature is very simple and efficient

2025-11-08

How does the `pagination` tag add and control pagination display for document lists to enhance user experience?

When building a website, as the amount of content grows, the document list page becomes long, which not only affects the page loading speed but also makes it difficult for visitors to find the information they need efficiently.At this time, adding pagination to the document list becomes a key factor in improving user experience.AnQiCMS provides a powerful `pagination` tag, combined with the document list tag `archiveList`, it can easily achieve this goal, making your website content display more professional and more user-friendly.

2025-11-08

How to dynamically fetch and display the global settings and contact information of the website using the `system` and `contact` tags?

In AnQi CMS, the global settings and contact information are the basic information that constitutes the important facade of the website.This information must be displayed accurately to visitors, and more importantly, it should be able to be updated and managed flexibly and conveniently without frequent modifications to the template code.AnQi CMS provides these two powerful tags, `system` and `contact`, allowing website operators to easily achieve dynamic acquisition and display of this information.

2025-11-08

How `tdk` tags can dynamically generate and optimize SEO-related Title, Keywords, and Description for each page?

In modern website operation, the importance of Search Engine Optimization (SEO) is self-evident, and the page title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, are the "business card" of the website content on the Search Engine Results Page (SERP).They not only directly affect the click-through rate of the page, but are also key factors for search engines to understand the content of the page and rank it.AnQiCMS (AnQiCMS) fully understands the significance of TDK for SEO, and therefore in the system design

2025-11-08