How to get the link address and display name of the navigation item in the AnQiCMS template?

Calendar 👁️ 69

As an experienced website operations expert, I fully understand the importance of an efficient and flexible CMS system for content operations.AnQiCMS with its powerful performance in Go language and the ease of use of the Django template engine indeed provides us with great convenience.Today, let's delve deeply into an essential topic in website template development: How to accurately obtain the link address and display name of navigation items in the AnQiCMS template?

Navigation, the soul path of the website

The navigation system is the skeleton of a website, guiding users through the information ocean, directly affecting user experience and SEO effects.A well-designed, easy-to-manage, and dynamically updateable navigation system is an indispensable part of a modern website.AnQiCMS provides an intuitive navigation management feature in the backend, allowing us to create multi-level navigation menus and apply them to different positions on the website, such as the top main navigation, sidebar, footer, and so on.

In the AnQiCMS backend settings, you will find the 'Navigation Settings' item.Here, you can create different navigation categories based on business needs, such as main navigation, footer navigation, or product navigation.Under each category, you can add specific navigation links, and specify their display names, subtitles, descriptions, and most importantly—the link type (built-in links, category page links, external links, etc.).All these flexible configurations ultimately need to be accurately called and displayed in the frontend template.

Core tags:navListMagic

In the AnQiCMS template system, to obtain navigation item data, we mainly rely on a powerful core tag:navListThis tag is the key bridge connecting the backend navigation configuration and the frontend display.

When you need to call the navigation list in a template, the basic way to use it is to wrap it in a{% navList 变量名 %}and{% endnavList %}Between. For example, you can name the navigation data obtainednavs:

{% navList navs %}
    {# 在这里处理您的导航数据 #}
{% endnavList %}

navListThe tag also supports some practical parameters that help us accurately filter and obtain the desired navigation menu:

  • typeIdThis is the key parameter for specifying the navigation category. Each navigation category created in the background will have a unique ID.For example, if your main navigation category ID is 1, then you can call it like this:{% navList navs with typeId=1 %}By changingtypeIdYou can easily call different navigation menus in different areas of the website.
  • siteId: If you are using the multi-site management feature of AnQiCMS and want to call the navigation data of a specific site (not the current site),siteIdthe parameter will come in handy.

In-depth acquisition of navigation item links and names

navListAfter the tag is executed, it will assign an array object containing all navigation items to the variable you define (for examplenavs)。Since this is an array, we need to usefora loop to iterate over each navigation item.

Inside the loop, each navigation item will be represented as aitemObject (Of course, you can customize the name of this loop variable). ThisitemThe object carries all the details of the navigation item, the most core of which is the link address and display name we are concerned about:

  • item.Title: This is the text name that the navigation item will display on the website.
  • item.LinkThis is the target URL address pointed to by the navigation item.

exceptTitleandLink,itemThe object also provides other useful properties to make our navigation more interactive and visually appealing:

  • item.SubTitle: If the background has set a subtitle for the navigation item, it can be obtained through this property.
  • item.Description: A brief description of the navigation item.
  • item.IsCurrentA boolean value indicating whether the current page being accessed matches the link of this navigation item. This is crucial for implementing the 'highlight the current active navigation item' feature.
  • item.NavListThis is the key to implementing multi-level navigation. If the current navigation item has child navigation (i.e., set as its subordinate in the background),item.NavListit will include one with the parent levelnavsA similar sub-navigation array, we can use it againforLoop nesting traversal.

Let's go through a specific code example to see how to build a common main navigation and handle the secondary menu:

<nav class="main-navigation">
    <ul>
        {% navList navs with typeId=1 %} {# 假设主导航的类别ID是1 #}
            {% for item in navs %}
                <li class="{% if item.IsCurrent %}active{% endif %}">
                    <a href="{{ item.Link }}">
                        {{ item.Title }}
                        {% if item.SubTitle %}<span>{{ item.SubTitle }}</span>{% endif %}
                    </a>

                    {% if item.NavList %} {# 判断是否有二级导航 #}
                        <ul class="sub-menu">
                            {% for subItem in item.NavList %}
                                <li class="{% if subItem.IsCurrent %}active{% endif %}">
                                    <a href="{{ subItem.Link }}">{{ subItem.Title }}</a>
                                </li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </li>
            {% endfor %}
        {% endnavList %}
    </ul>
</nav>

In this example, we first usenavListObtaintypeIdNavigation data for 1. Then, through the firstforLoop through each top-level navigation item (item) and print its title (item.Title) and link (item.Link)。We also useitem.IsCurrentto add the corresponding navigation item for the current pageactiveA class, to implement visual highlighting. For the ones containing sub-navigation,itemwe use{% if item.NavList %}to make the judgment, and internally use the secondforLoopsubItemto render the links and names of the second-level navigation.

The advantages and flexibility of AnQiCMS

The design philosophy of AnQiCMS is fully reflected in the navigation management.By clearly separating navigation data from template logic, as operators, we can easily adjust the menu structure, modify links, and even switch navigation between different language sites without touching a single line of code.navListThe powerful functionality of tags, building a navigation system that is both beautiful and practical.

Its high-performance architecture of Go language also ensures that even complex navigation structures can be rendered quickly, without slowing down the website loading speed, thus providing users with a smooth browsing experience.

Frequently Asked Questions (FAQ)

  1. Ask: How to display multiple different navigation menus on a single page, such as the main navigation and footer navigation?

    • Answer:In the AnQiCMS background 'Navigation Settings', you can create multiple 'Navigation Categories', each with a unique ID. In the template, you just need to call it multiple timesnavListLabel, and throughtypeIdSpecify the navigation category ID for different parameters. For example,{% navList headerNavs with typeId=1 %}used for the main navigation, while{% navList footerNavs with typeId=2 %}is used for footer navigation.
  2. Question: How many levels of sub-menus does AnQiCMS navigation menu support at most?

    • Answer:Based on the document description of AnQiCMS, its navigation list tagNavListThe field structure supports navigation links up to two levels. This means you can implement a primary menu and its sub-menu at one level, totaling two layers of structure.
  3. Ask: Can I add dynamic parameters to the link of navigation items, or display different navigation items based on the user's login status?

    • Answer: item.LinkThis is the final link address configured on the backend, which is usually a static or pseudo-static URL.If you need more complex dynamic parameters, you can configure it as an "external link" in the background and manually enter a URL with parameters.forLoop throughitemWhen, combined with the current page user login status variable (if such a variable is provided by your template context), perform conditional judgment ({% if user.is_logged_in %}Thus, it decides whether to render a navigation item. However, AnQiCMS currently does not provide a parameter for user status judgment directly in the navigation tag.

Related articles

How to specify different navigation categories with the `typeId` parameter of AnQiCMS navigation tags?

As an experienced website operations expert, I know that a flexible and efficient navigation system is crucial for website user experience and Search Engine Optimization (SEO).AnQiCMS does an excellent job in this aspect, it provides great convenience for the customization of website navigation through its powerful template tag system, especially with the `navList` tag配合`typeId` parameter.Today, let's delve deep into the mysteries of this `typeId` parameter and how to cleverly use it to manage different types of navigation categories.

2025-11-07

How to create a new navigation category in the AnQiCMS backend, such as footer navigation or sidebar navigation?

## Unlock a new dimension of website layout: easily create custom navigation categories in AnQi CMS background As an experienced website operations expert, I am well aware of the importance of a flexible and efficient content management system for website success.AnQiCMS, with its high-performance architecture based on the Go language, modular design, and SEO-friendly features, has become the first choice for many small and medium-sized enterprises and content operation teams.Its strong performance in content management, not only reflected in the publication and management of core content such as articles and products, but also in its highly customizable navigation system

2025-11-07

How to determine the currently active (active) navigation item in the AnQiCMS navigation list?

As an experienced website operation expert, I fully understand the importance of navigation menus for user experience and website structure.An active navigation item that can clearly indicate the current position, not only can it improve the user's browsing efficiency, but also provide positive visual feedback.In such an efficient and user-friendly content management system as AnQiCMS (安企CMS), the realization of this feature is equally concise and powerful.Today, let's delve into how to cleverly judge and mark the currently active navigation item in the AnQiCMS navigation list, making your website navigation smarter and smoother

2025-11-07

How to use AnQiCMS navigation list tags to display two-level or multi-level menu structures?

The operation of a website is like steering a ship, and a clear navigation system is like a compass guiding the direction.In the world of content management, a high-efficiency, flexible navigation menu can not only greatly enhance the user experience, allowing visitors to navigate your website freely, but is also an important foundation for optimizing website structure and improving search engine friendliness.AnQiCMS (AnQiCMS) fully understands its way, providing users with a powerful and intuitive navigation list tag, making it easy to build a multi-level menu structure.Today, let's delve into how to skillfully use the `navList` tag in AnQiCMS

2025-11-07

How is the display order of AnQiCMS navigation menu items managed and adjusted in the backend?

As an experienced website operation expert, I am well-versed in all the functions of AnQiCMS, especially its design concepts in content management and user experience optimization.Today, let's delve into a seemingly simple but crucial feature for website structure and user experience: how the display order of AnQiCMS navigation menu items is managed and adjusted in the background.A clear and logical navigation menu is the foundation of a successful website.It not only helps users find the information they need quickly, but it is also an important basis for search engines to understand the structure of websites.

2025-11-07

Does AnQiCMS support adding external links in the navigation menu and how to set it up?

## SecureCMS Navigation Menu: Easily integrate external links to expand your website ecosystem In today's fast-paced digital world, an efficient and user-friendly website navigation system is undoubtedly a guiding light for users visiting the website.It not only guides visitors to deeply explore your content, but is also the key to connecting the brand ecosystem and enhancing the user experience.As an experienced website operations expert, I fully understand the importance of the flexibility of the navigation menu for content strategy, especially whether it can add external links.

2025-11-07

How to call the link of category page or single page in AnQiCMS navigation list?

The Anqi CMS plays a core role in website operations, and the navigation system is a guide for users to explore the website's content.A well-designed and convenient navigation not only enhances user experience but is also a key aspect of search engine optimization.Today, we will delve into how to flexibly integrate category pages and single-page links巧妙地融入到 websites navigation list.### Navigation Configuration: The Bridge from Backend to Frontend The navigation system of AnQiCMS is designed to be very intuitive and powerful, closely integrating the configuration of navigation with the call of front-end templates

2025-11-07

What are the cases where the `PageId` field of AnQiCMS navigation items takes effect?

## AnQiCMS navigation item's `PageId` field: When does it unleash the magic of precise navigation?In AnQiCMS (AnQiCMS) such a rich-featured and highly customizable content management system, each configuration item carries a specific mission.Navigation serves as the skeleton of a website, its importance is self-evident.When delving into the navigation settings of AnQiCMS, you will find a field named `PageId`.

2025-11-07