How to generate and display breadcrumb navigation in the AnQiCMS template?

Calendar 👁️ 58

In website operation, a clear navigation structure is crucial for improving user experience and search engine optimization (SEO).Imagine if, as a visitor delves deep into your website, there were a path guide that told them 'You are here', wouldn't it make them feel secure and convenient?This is the function of Breadcrumb Navigation.It is like breadcrumbs scattered in fairy tales, helping users easily backtrack in the website and understand the position of the current page in the overall website structure.

In AnQiCMS, due to its flexible template mechanism and SEO-friendly design, adding breadcrumb navigation to the website becomes extremely simple and efficient.This article will guide you step by step on how to generate and display this practical navigation element in the AnQiCMS template.

Understand the core mechanism of breadcrumb navigation in AnQiCMS

AnQiCMS provides a namedbreadcrumbA dedicated template tag, it can automatically generate a navigation path data according to the URL structure of the current page.The use of this tag is very intuitive, we usually place it at the top of the page to provide visitors with a clear 'home path'.

While usingbreadcrumbWhen labeling, you need to define a variable name to receive the generated breadcrumb data, for examplecrumbs. ThiscrumbsThe variable will be an array object containing multiple navigation items, each withName(link name) andLink(Link address) These two key properties. By traversing this array, we can dynamically build a complete breadcrumb navigation on the page.

Detailed steps: Implement breadcrumb navigation in AnQiCMS template

Step 1: Prepare the breadcrumb code snippet file

To make the breadcrumb navigation easily accessible on all pages and maintain the cleanliness and modularization of the code, we strongly recommend placing the breadcrumb code in a separate template snippet file. According to the AnQiCMS template conventions, such snippet files are usually placed intemplate/你的模板目录/partial/directory.

You can create a file namedbreadcrumb.htmlwith the path similar to:/template/你的模板目录/partial/breadcrumb.html.

Step two: write the breadcrumb navigation template code

in the newly createdbreadcrumb.htmlin the file, we will utilizebreadcrumbTags andforLoop to build the HTML structure for breadcrumb navigation.

This is a commonly used breadcrumb navigation code example, which not only generates the navigation path but also considers the highlight of the current page:

<nav aria-label="breadcrumb">
    <ol class="breadcrumb">
        {%- breadcrumb crumbs with index="首页" title=true %}
        {%- for item in crumbs %}
            {%- if forloop.Last %}
                {# 最后一个导航项(当前页),不加链接,并标记为 active #}
                <li class="breadcrumb-item active" aria-current="page">{{ item.Name }}</li>
            {%- else %}
                {# 其他导航项,带有链接 #}
                <li class="breadcrumb-item"><a href="{{ item.Link }}">{{ item.Name }}</a></li>
            {%- endif %}
        {%- endfor %}
        {%- endbreadcrumb %}
    </ol>
</nav>

In this code snippet:

  • {%- breadcrumb crumbs ... %}The breadcrumb data is assigned tocrumbsVariable.
  • {%- for item in crumbs %}Loop through each breadcrumb navigation item.
  • forloop.LastIt is a very useful built-in variable, used to determine whether the current loop is the last item.We use it to distinguish the current page (usually non-clickable) from other clickable parent pages.
  • item.NameDisplay the text of the navigation item,item.LinkProvide the link address of the navigation item.
  • {%-and-}Remove the whitespace from the line where the tag is located, making the final output HTML more tidy.

Step 3: Customize the display behavior of the breadcrumb navigation.

breadcrumbThe tag provides several parameters to allow flexible control of the breadcrumb display:

  1. indexParameter: Set the home page nameBy default,breadcrumbThe label will display the navigation starting point as "Home". If you want to change this name, for example to "My Blog" or "Homepage", simply adjust itindexParameters can be used. For example:{% breadcrumb crumbs with index="我的网站主页" %}

  2. titleParameter: Controls the display of the current page titleFor document detail pages or single pages, you may want the last item in the breadcrumb to be the title of the current page.titleThe parameters come into play.

    • title=true(Default): It will automatically display the title of the current page (such as the article title, product name, etc.).
    • title=false: The title of the current page will not be displayed.
    • title="自定义文本"If you want to display a fixed word consistently, such as on the article detail pagetitle='文章内容'it will display this customized text.

    You can flexibly set it according to the page type or design requirementstitleParameter.

  3. siteIdParameter (multi-site scenario)If you have enabled the multi-site management feature in AnQiCMS and want to call data from other sites on a specific site,breadcrumbTags also supportsiteIdParameter. However, in most single-site cases, you usually do not need to care about this parameter.

Step 4: Introduce breadcrumb navigation on the page

Having an independentbreadcrumb.htmlAfter the file, you just need to place the breadcrumb in the template file where you need it (for exampledetail.htmlorlist.html), usingincludeLabel it to introduce. Usually, breadcrumbs are placed above the main content area of the page, or immediately after the website header navigation.

`twig {% extends ‘base.html’ %} {# Assume the page inherits base.html #}

{% block header %}

{# 你的网站头部导航代码 #}

{% endblock %}

{% block main_content %}

{# 在这里引入面包屑导航 #}
{% include "partial/breadcrumb.html" %}

{# 页面主内容区域 #}
<div class="page-content">
    <h1>欢迎来到 {{ pageTitle }}</h1>
    <p>这是页面的详细内容...</p>
</div>

{%

Related articles

How to display the friend link list on the AnQiCMS website?

Friend links are an indispensable part of website operation, as they not only promote communication and cooperation between websites, but also have a positive effect on SEO optimization.In AnQiCMS, displaying the friend link list is a simple and efficient process, allowing website administrators to easily provide visitors with more valuable external resources. ### Backend Management: Configure Your友情链接 Firstly, you need to configure the友情链接 in the backend of AnQiCMS in order to display it on the front page.

2025-11-07

How to display single page content in AnQiCMS, such as the "About Us" or "Contact Us" page?

Displaying single-page content such as 'About Us' or 'Contact Us' in AnQiCMS is a very intuitive and flexible process.The system is designed to meet the needs of such static information display, through simple backend management and powerful template rendering capabilities, allowing you to easily create and beautify these important web pages. ### Create and Manage Single Page in the Back-end Firstly, all the content of single pages needs to be created and managed in the AnQiCMS back-end.

2025-11-07

How to implement lazy loading (lazyload) feature in AnQiCMS article content?

On your AnQiCMS website, optimizing image loading is a key step to improving user experience and website performance, especially for pages with a large number of image content.The Lazy Load (Lazy Load) technology is an efficient solution that allows the page to only load images within the user's viewport, while deferring the loading of images outside the viewport until the user scrolls near them.This can significantly reduce the initial page loading time, save bandwidth, and improve the overall website response speed.

2025-11-07

How to enable Markdown editor in AnQiCMS and ensure that mathematical formulas and flowcharts are displayed correctly on the webpage?

AnQiCMS provides a flexible and diverse editing experience for content creators, and the introduction of the Markdown editor has made it even more convenient for many users who are familiar with this concise markup language.However, simply enabling the Markdown editor is not enough for content that requires special rendering, such as mathematical formulas and flowcharts.This article will provide a detailed guide on how to enable Markdown editor in AnQiCMS and ensure that your web page can correctly and beautifully display complex mathematical formulas and flowcharts.### One, Enable

2025-11-07

How to display the unique field content according to a custom content model?

AnQi CMS with its powerful content management capabilities, especially the flexible content model, makes the organization of our website content simpler than ever before.When the standard content field cannot meet specific business needs, a custom content model and its unique fields emerge.How can you accurately call and display these unique custom field contents in the website front-end template?This article will detail the mysteries revealed for you. ### 1. Understanding the content model and custom fields of AnQi CMS One of the core strengths of AnQi CMS is its highly flexible content model

2025-11-07

How to call and display data from different sites in AnQiCMS multi-site management?

AnQiCMS (AnQiCMS) as an efficient and flexible content management system, its powerful multi-site management function is undoubtedly a highlight favored by many operators.When we hold multiple brand, multiple region, or multiple theme websites, we can manage them uniformly through a system and flexibly call and display data between different sites, which will greatly improve work efficiency and content integration.How can we implement the calling and display of data between different sites in the AnQiCMS multi-site environment?### Understanding the core of multi-site data calls

2025-11-07

How to loop through and display the article tag list in AnQiCMS templates?

In Anqi CMS, article tags are not only a tool for organizing content and improving user experience, but also an important element for optimizing search engine crawling and ranking (SEO).They can help visitors quickly find relevant content and can also help search engines better understand the website structure.How can I flexibly loop through and display these article tag lists in the AnQiCMS template?This is actually simpler than you imagine, the powerful template tag system of AnQiCMS makes everything very intuitive.

2025-11-07

How to implement multi-language content switching and display on AnQiCMS websites?

Under the wave of globalization, website multilingual support has become a necessary condition for enterprises to expand into the international market.AnQiCMS as an enterprise-level content management system, fully considers this requirement and provides a set of efficient and flexible solutions to help users easily switch and display multilingual content. ### AnQiCMS implementation logic for multilingual The core strategy of AnQiCMS for switching and displaying multilingual content is based on its powerful "multi-site management" function.

2025-11-07