How does AnQiCMS use the `navList` tag to build and display multi-level website navigation menus?

Calendar 78

When building a feature-rich website, a clear and intuitive navigation menu is the core of user experience. AnQiCMS provides a powerful template tag system, wherenavListThe tag is specifically used to build and display multi-level navigation menus on websites.It not only can display the navigation structure you configure in the background, but also helps you convert technical details into user-friendly interactive experiences.

The foundation of navigation construction: backend settings

While usingnavListBefore the label, you first need to configure the navigation menu in the AnQiCMS backend management interface.You can flexibly define the navigation structure of the website through the 'Background Settings' menu under the 'Navigation Settings' feature.

Navigate to the navigation settings page and you will find that the system provides a default "default navigation" category, but you can also create multiple custom navigation categories according to the website layout needs, such as "footer navigation" or "sidebar navigation". Each navigation category has a uniquetypeIdThis will be used in subsequent frontend calls.

In the specific navigation link settings, you can specify the 'Display Name', 'Subtitle Name', and 'Navigation Description' for each menu item, all of which can be called in the front-end template.Moreover, the 'link type' determines where the navigation item points to, you can choose to link to the built-in homepage, a specific category page, a single page, or even an external link.

The key to implementing multi-level navigation is the 'Parent Navigation' option.By selecting an existing main menu item as the "parent navigation" for a submenu item, you can easily create a menu structure with clear levels.AnQiCMS currently supports navigation links up to two levels, that is, a main menu item can contain a first-level submenu.

navListLabel: Magic of frontend navigation

Once the backend navigation structure is configured, it can be used in the frontend template.navListLabels will render them.navListThe usage of tags is very intuitive:

{% navList navs %}
    {# 你的导航结构代码 #}
{% endnavList %}

Here, navsis a variable name you can customize, it will receivenavListThe label returns a navigation data collection. This collection is an array object, with each element representing a navigation item, you can useforto iterate over it.

navListThe label supports several important parameters:

  • typeIdThis parameter allows you to specify which navigation category of data to retrieve. For example, if you create one in the background,typeIdFor the "footer navigation" of 2, so when called in the front-end, it can be written as{% navList footerNavs with typeId=2 %}.
  • siteIdIf you use the multi-site management feature of AnQiCMS and want to call data from other sites, you can specify the site ID through this parameter.For single-site users, this parameter is usually not required.

InforIn the loop, each navigation item (such as the code above)itemVariables all contain a series of useful fields that can be used to build rich navigation elements:

  • Title: The display name of the navigation item.
  • SubTitle: If a subtitle is set in the background, it can be obtained here.
  • Description: Description information of navigation items.
  • Link: The URL address pointed to by the navigation item.
  • IsCurrent: A boolean value indicating whether the current navigation item is a link to the current page, often used to highlight the active state.
  • NavListThis is the key to implementing multi-level navigation! If the current navigation item has a submenu,NavListit will be a new array of navigation items, and you can nest it byforlooping to render the submenu.
  • PageId: If the navigation item links to a category or a single page, the corresponding ID will be stored here. This is very useful when it comes to dynamically loading other content related to the navigation item.

Apply in practice: Build multi-level navigation menus

Let's see through several practical examplesnavListHow to flexibly build different types of multi-level navigation.

1. Build a basic two-level dropdown menu

This is the most common navigation form, with a dropdown submenu under the main menu.

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

This code first traverses all top-level navigation items, if a navigation item'sNavListThe field is not empty, which means it has a submenu, and then an inner loop will be entered to render these submenus.IsCurrentThe field can help you add navigation items to the current page.activeto provide visual feedback.

2. Navigate dropdown to display related products

If your website is a product showcase type, you may want to display several popular products under the navigation item of a product category when the user hovers over it. This can be done byPageIdandarchiveListTag combination implementation.

Assuming there is a main menu "Product Category" in the background navigation menu, under which there is a submenu "Electronics", and this submenu links to a product category page.

<nav class="product-navigation">
    <ul>
        {% navList navs with typeId=1 %} {# 假设产品导航使用默认typeId=1 #}
            {% for item in navs %}
                <li>
                    <a href="{{ item.Link }}">{{ item.Title }}</a>
                    {% if item.NavList %}
                        <div class="dropdown-content">
                            {% for inner in item.NavList %}
                                <div class="category-block">
                                    <h4><a href="{{ inner.Link }}">{{ inner.Title }}</a></h4>
                                    {% if inner.PageId > 0 %}
                                        {# 如果这个子菜单链接的是一个分类页面,则显示该分类下的产品 #}
                                        <ul class="product-list">
                                            {% archiveList products with type="list" categoryId=inner.PageId limit="4" %}
                                                {% for product in products %}
                                                    <li><a href="{{ product.Link }}">{{ product.Title }}</a></li>
                                                {% endfor %}
                                            {% endarchiveList %}
                                        </ul>
                                    {% endif %}
                                </div>
                            {% endfor %}
                        </div>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

In this example, when traversing to the sub-navigation iteminnerwe checkinner.PageIdwhether it is greater than 0. If it indeed points to a category, it usesarchiveListto pass the tag,categoryId=inner.PageIdto retrieve and display the product list under the category.

3. Navigation dropdown to display subcategories

Another common requirement is that when the main menu item is a certain large category, the dropdown menu can directly display its subordinate subcategories.

`twig

Related articles

How to obtain and display the contact information of the website in AnQiCMS, such as phone, email, address, and social media links?

It is crucial to clearly display contact information when building and operating a website to establish user trust and provide customer support.AnQiCMS as an efficient content management system provides an intuitive way to manage and display this key information, whether it is traditional phone numbers, email addresses, or modern social media links, it can be easily realized. ### One, Back-end Configuration: Centralize Your Contact Information AnQiCMS has designed a centralized area for you to manage all website contact information in one place.

2025-11-07

How to retrieve and display the system global settings of AnQiCMS template, such as website name, Logo, filing number, and copyright information?

When building a website, some core information such as the website name, website logo, filing number, and copyright information are indispensable elements.These global settings not only help visitors quickly identify your brand, but also reflect the professionalism and compliance of the website.AnQiCMS provides a straightforward and flexible way to manage and present these system-level information in templates.Where can I set these global information?First, these important website information need to be unified configured in the AnQiCMS background.

2025-11-07

How to retrieve and display the list of Tag tags and their corresponding links for an article?

In a website with increasingly rich content, how to effectively organize and present information is crucial.The Tag label (usually referred to as keywords or tags) not only helps users find related content quickly, but is also an indispensable part of Search Engine Optimization (SEO).AnQi CMS understands this point, providing users with a powerful and flexible tagging function, allowing you to easily add tags to articles and display these tags and their corresponding links in multiple forms on the website front end.

2025-11-07

How to dynamically retrieve and display the content of custom model fields for an article in a template?

In AnQi CMS, the flexibility of website content is one of the key advantages for our content operation and website layout.By customizing content model fields, you can add unique properties for different types of content (such as articles, products), which can better reflect your business needs.But how can we dynamically present these carefully defined custom field contents in the front-end template of the website?This article will discuss this topic in detail, helping you fully utilize the powerful functions of AnQiCMS.

2025-11-07

How to display breadcrumb navigation in AnQiCMS template and customize the home page name or whether to include the current page title?

Have you ever felt a bit confused while browsing websites, not knowing where you are?Breadcrumb Navigation is like leaving a series of small markers along the way as you explore a new place, making it clear where you came from and where you are now.It can significantly enhance the user experience of the website, help visitors quickly understand the website structure, and is very beneficial for search engine optimization (SEO), as it provides clear website hierarchy information for search engine spiders.

2025-11-07

How AnQiCMS dynamically generates and displays page Title, Keywords, and Description (TDK) to optimize SEO?

In website operation, to make your content stand out in search engines, attract more target users, and cannot do without the careful setting of these three core elements: Title, Keywords, and Description (TDK).AnQiCMS knows the importance of TDK for SEO, and has integrated a complete dynamic TDK generation and management mechanism from the beginning of the system design, allowing you to flexibly and efficiently optimize every page of your website.

2025-11-07

How to enable multilingual support for AnQiCMS website and display language switch options in the front-end template?

Under the wave of globalization, websites no longer only serve local users. How to allow visitors from different language backgrounds to access and understand the content of the website without barriers has become an important challenge for many operators.AnQiCMS (AnQiCMS) fully understands this need, providing a flexible and powerful multilingual support solution to help websites easily expand into the international market.This article will introduce how to enable multilingual functionality on the AnQiCMS website and guide you to integrate language switching options in the front-end template to enhance user experience.

2025-11-07

How does AnQiCMS handle and display image resources, including automatic compression, conversion to WebP format, and watermark management?

In website content operation, images are indispensable elements to attract visitors and convey information, but their size, loading speed, and copyright protection are also focuses for operators.AnQiCMS as a content management system is well-versed in this field, therefore, it has integrated a series of intelligent image resource processing and optimization functions, aiming to help us manage website images more efficiently and effortlessly, and improve user experience and SEO performance.

2025-11-07