How to implement dynamic display of breadcrumb navigation in AnQi CMS templates?

Calendar 👁️ 63

In website operation, Breadcrumb Navigation plays a crucial role.It can not only visually display the user's position hierarchy on the website, helping users understand the relationship between the current page and the entire website structure, but also effectively improve the user experience, reduce the bounce rate, and have a positive impact on search engine optimization (SEO).For websites built using AnQiCMS, implementing dynamic breadcrumb navigation is a simple and efficient feature enhancement.

AnQiCMS as an enterprise-level content management system developed based on the Go language, its template system adopts syntax similar to the Django template engine, making the creation of templates and the invocation of content very intuitive. The system is built with a rich set of template tags, including those specifically designed for generating breadcrumb navigation.breadcrumbLabel. The clever design of this label greatly simplifies the work of developers, allowing us to easily dynamically display breadcrumb navigation that matches the current page path on various pages of the website (whether it is the homepage, category list page, article detail page, or single page).

Skillfully utilize the built-in features of AnQiCMSbreadcrumbTag

To implement the dynamic display of breadcrumb navigation, the core is to make use of the features provided by AnQiCMSbreadcrumbThe tag can automatically identify the type and hierarchy of the current page and generate a list of all hierarchical paths.

First, let's get to knowbreadcrumbThe basic structure and common parameters of tags:

{% breadcrumb crumbs with index="首页" title=true %}
    {# 循环输出面包屑路径 #}
{% endbreadcrumb %}

Here:

  • crumbsis a variable name we define to storebreadcrumbThe breadcrumb path list generated by the tag. You can use any variable name you think is appropriate.
  • index="首页"This parameter is used to set the display name of the home page in the breadcrumb navigation.By default, it will display as "Home
  • title=trueThis parameter mainly takes effect in articles or single-page detail pages, it determines whether the title of the current page is displayed as the last item in the breadcrumb path. If set totrueIt will display the full document title if set tofalseThe title will not be displayed if set totitle="文章详情"This will always display as "Article Details" regardless of the current article title.
  • siteIdIn most cases, you do not need to set it manually, but if you have configured multi-site management in the AnQiCMS backend and need to call data from a specific site to generate breadcrumbs, you can specify the site ID with this parameter.

WhenbreadcrumbAfter the label is executed, it will assign the generated breadcrumb path to an array object.crumbsVariable. Each element in this array represents a level in the path, and each element contains two key fields:

  • Name: Indicates the display name of the level (for example, "News Center", "Company Profile", or article title).
  • Link: Indicates the URL address corresponding to the level.

Integrate breadcrumb navigation into the template

UnderstoodbreadcrumbAfter understanding the principle of tags, integrating it into your AnQiCMS template becomes very simple.The breadcrumb navigation is usually placed at the top content area of the website page, such as below the header or above the main content.

Here is an example of a typical breadcrumb navigation code, you can place it in your template file (such asdetail.html/list.htmlorindex.htmlor even publicpartial/header.htmlorbase.htmlThrough, andincludeorextendsIntroduced):

<nav class="breadcrumb-nav">
    <ol class="breadcrumb">
        {% breadcrumb crumbs with index="首页" title=true %}
            {% for item in crumbs %}
                <li class="breadcrumb-item">
                    {% if not loop.last %} {# 判断是否是最后一个元素 #}
                        <a href="{{ item.Link }}">{{ item.Name }}</a>
                        <span class="breadcrumb-separator">/</span>
                    {% else %}
                        <span>{{ item.Name }}</span> {# 最后一个元素通常不带链接 #}
                    {% endif %}
                </li>
            {% endfor %}
        {% endbreadcrumb %}
    </ol>
</nav>

In this code block:

  1. We use{% breadcrumb crumbs with index="首页" title=true %}Tag to get breadcrumb data and store it incrumbsthe variable.
  2. {% for item in crumbs %}The loop will iterate overcrumbsEach level of the breadcrumb array.
  3. loop.lastIsfora special variable provided by the loop to determine the current loop iterationitemIs it the last element in the array. Usually, the last item of the breadcrumb navigation only displays text and does not contain links.
  4. {{ item.Link }}and{{ item.Name }}Then the links and names of each level were output separately.
  5. breadcrumb-separatorandbreadcrumb-itemThese CSS class names, you can adjust them according to your website design, and beautify the breadcrumb display effect through CSS styles, so that it matches the overall style of your website.

In this way, no matter which page the user visits, AnQiCMS will automatically generate and display the corresponding breadcrumb navigation according to the actual path of the current page.For example, when a user enters the "Product Center

This dynamic implementation not only saves a lot of time manually coding, but also ensures the accuracy and consistency of website navigation, thereby providing visitors with a seamless and pleasant browsing experience.

Summary

AnQiCMS with its powerful template tag system makes it extremely simple and efficient to implement dynamic breadcrumb navigation on the website.Just a few lines of template code can significantly improve the user experience and search engine optimization of your website.breadcrumbTags and their flexible parameter configuration can help you easily build high-quality websites with clear structure and convenient navigation.

Frequently Asked Questions (FAQ)

Q1: What should I do if the breadcrumb navigation does not display or displays incorrectly?A1: Please check firstbreadcrumbAre the labels spelled correctly, parameters?indexandtitleIs the value set as expected. Secondly, confirm that your page data (such as category ID, article title, etc.) has been loaded correctly. In development mode, you can try using{{ crumbs|dump }}(to importtag-filters.mdindumpFilter) or output temporarily in the template{{ crumbs }}To viewcrumbsWhether the variable contains the expected data structure. IfcrumbsEmpty, it may be that the current page cannot recognize its level or the data has not been passed correctly. Please check the page category or article ID to ensure it is valid.

Q2: How to customize the breadcrumb navigation style?A2: The code example provided in the article used<nav class="breadcrumb-nav">/<ol class="breadcrumb">and<li class="breadcrumb-item">such HTML structure and CSS class names. You can edit the CSS file of the website (usually located/public/static/css/Under the directory), customize the style rules for these class names, such as adjusting font size, color, spacing, background, etc., to perfectly blend with your website design style.AnQiCMS advocates for the separation of style and content, making it convenient for you to make flexible visual adjustments.

Q3:titlethe parameter totrueWhat is the difference between setting it and setting a specific string?A3: Whentitlethe parameter totrueAt the time, on the article or single-page detail page, the last item of the breadcrumb navigation will dynamically display the actual title of the current page (for example, the title of the article'sTitleField value).For example, if you set it to a specific stringtitle="最新动态"Then no matter what the actual title of the current page is, the last item of the breadcrumb will be displayed as the string you specified, "latest dynamic".This is very useful when you want to use unified final navigation text for a specific page type.

Related articles

How can AnQi CMS ensure that the HTML content in the rich text editor is secure and displayed correctly?

In website content management, the use of rich text editors greatly facilitates the creation and beautification of content.However, ensuring that the HTML content entered by the user is both safe and correctly displayed on the front end while allowing free formatting is a core challenge that every content management system must face.AnQiCMS as an enterprise-level content management system provides multi-layered security mechanisms in this regard.Firstly, AnQiCMS has established a solid security foundation from the bottom of the system architecture.

2025-11-08

How to use the Tag feature of AnQi CMS to display related content aggregation pages on the front end?

The AnQi CMS provides a powerful and flexible tag (Tag) feature that helps us better organize content, improve the website's SEO performance, and provide users with a more convenient way to discover content.By making good use of tags, we can easily create content aggregation pages, allowing visitors to quickly find related articles or products based on their interests.Understanding the Core Value of Tag FunctionWhen we assign one or more tags to a document

2025-11-08

How to display the directory or title structure of article content in AnQi CMS?

On a content-rich website, providing a clear table of contents or title structure for long articles can greatly enhance the user's reading experience and also help search engines better understand the hierarchy of page content, thereby having a positive impact on SEO performance.AnQi CMS is well-versed in this and provides flexible and powerful features to easily meet this requirement.

2025-11-08

How to obtain and display custom parameter fields on the Anqi CMS article detail page?

In website operation, we often need to display personalized information beyond standard titles, content, and publication dates.AnQi CMS, with its highly flexible content model, gives us the ability to add custom parameter fields to articles, products, and other content, thereby meeting various diverse display needs.This article will thoroughly explain how to obtain and elegantly present these custom parameter fields on the article detail page of Anqi CMS, making your content more expressive.

2025-11-08

How to crop and process the thumbnail size of articles in AnQi CMS to adapt to different display requirements?

In website content operation, images, especially thumbnails, play a crucial role.They are not only the first line of defense in attracting user clicks, but also the key to adapting to different devices and layout formats.A high-efficiency website content management system should provide a flexible thumbnail processing mechanism.AnQiCMS (AnQiCMS) considers this aspect thoroughly, providing a series of powerful features to help us easily manage and optimize article thumbnails to meet various display needs.### The Source and Intelligence Generation of Thumbnails The acquisition of article thumbnails in AnQi CMS is very flexible

2025-11-08

How to set the SEO title, keywords, and description (TDK) of a website to display in search results in Anqi CMS?

## Optimize Search Visibility: Detailed Guide to Fine-tuning Website SEO Title, Keywords, and Description (TDK) in AnQi CMS In the digital world, the visibility of a website is the key to its success.When a user searches for information through a search engine, the way your website is displayed in the search results directly affects whether they will click to enter.This, the website's SEO title (Title), keywords (Keywords), and description (Description), which we commonly refer to as TDK, play a crucial role

2025-11-08

Does AnQi CMS support rendering Markdown formatted text in the content as HTML?

Anqi CMS is an efficient and customizable content management system that has always been committed to providing modern and convenient solutions in content creation and presentation.For many content creators, Markdown, with its concise and efficient features, has become an indispensable tool for daily writing.Then, does AnQi CMS support Markdown formatted text and render it as HTML to display normally on the front-end page?The answer is affirmative, Anqi CMS provides comprehensive support for Markdown, with high integration and smooth operation. Firstly

2025-11-08

How to implement the hierarchical display of custom navigation menus in Anqi CMS templates?

To implement hierarchical display of custom navigation menus in AnQi CMS is an important link to improve the user experience and content organization of the website.AnQiCMS provides flexible backend configuration and powerful template tags, allowing users to easily build clear and easy-to-navigate multi-level navigation menus. ### Customize Navigation Menu in Backend To achieve hierarchical display of the navigation menu, you first need to make the corresponding configuration in the AnQiCMS backend.In the background management interface, find the "Background Settings" menu under the "Navigation Settings" option

2025-11-08