How to use the `for` loop to iterate over all single pages returned by the `pageList` tag in the AnQiCMS template?

Calendar 👁️ 61

In the world of AnQiCMS, the flexibility and efficient management of content are its core advantages.Whether it is to publish corporate news, product details, or build a complex content matrix for multiple sites, AnQiCMS can provide powerful and intuitive support.Today, as an expert operator who understands the way, I want to talk to everyone about a very practical skill in AnQiCMS template making: how to use it cleverlyforLoop tag to iterate and displaypageListAll single page content returned by the tag.

AnQiCMS Single Page: Flexible Content Foundation

Let's briefly review the 'single-page' feature in AnQiCMS.In the background, we can easily create and manage various independent pages, such as "About Us", "Contact Information", "Service Details", or any other pages that need to be displayed separately and have relatively fixed content.These single pages not only support custom URLs, SEO titles, keywords, and descriptions, but also allow for independent templates and Banner images, greatly enriching the expression form of the website content.They are an indispensable part of building a website's basic information and core business introduction.

However, it is not enough to have created these pages in the background; we also need to dynamically display them on the website front-end, such as as part of the navigation menu or in a specific area to showcase all service pages.At this moment, the powerful template tags and loop control of AnQiCMS come into play.

Core tags:pageList--Get all single page data

To traverse a single page, we first need to extract the data of these pages. AnQiCMS provides a special template tag for this.pageList. Its use is very direct and concise.

When you write in the template{% pageList pages %}the system will automatically retrieve all the single page data that has been created and store them in a folder namedpages. ThispagesA variable is an array object, each element representing a complete piece of information for a single page.pageListThe tag itself does not require complex parameter configuration, the default can be used to get all single pages on the entire site, which lays a solid foundation for our subsequent traversal operations. Of course, if you are in a multi-site environment and need to get data for specific sites,pageListit also supports getting throughsiteIdThe parameter can be specified, but the default usage is sufficient for most cases.

Each single page (which we usually call it in a loop)item) carries rich field information, such asId(Single Page ID),Title(Title),Link(Page Link),Description(Description),Content(Page Content),Logo(Thumbnail Full Image) andThumb(Thumbnail) etc. These fields allow us to flexibly display various aspects of the page in the front-end template.

Efficient iteration:forLoop throughpageListdata

OncepageListTo fill the single-page data intopagesIn the variable, we can call out another very powerful tag in the AnQiCMS template——forLoop.forThe loop tag is specifically used to iterate over arrays, slices, or other iterable objects, allowing us to access them one by onepagesEach single page in the variable, and present its content on the web page.

The most basicforThe loop syntax is as follows:

{% pageList pages %}
    {% for item in pages %}
        {# 在这里可以访问item的各种属性 #}
        <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
        <p>{{ item.Description }}</p>
    {% endfor %}
{% endpageList %}

In this code block,itemIt represents a temporary variable for the current single page in each loop. Throughitem.Title/item.LinkIn this way, we can easily obtain and display the title and link of each single page.

Advanced application and consideration

In actual project development, we often need more fine-grained control and richer display effects. AnQiCMS'sforLoop tags provide a variety of auxiliary functions, making template development more intuitive.

  1. Handle empty list:{% empty %}The elegant fallback.IfpageListNo single page is returned, we do not want the page to be blank or show errors. At this point,forrepeatedly{% empty %}the branch becomes particularly important. It allows us to provide a friendly prompt when the data is empty:

    {% pageList pages %}
        {% for item in pages %}
            {# ... 展示单页面内容 ... #}
        {% empty %}
            <p>目前还没有任何单页面内容发布。</p>
        {% endfor %}
    {% endpageList %}
    
  2. Loop auxiliary variable: master each iterationInforInside the loop, AnQiCMS provides some built-in loop auxiliary variables that can help us better control the display logic of content:

    • forloop.Counter: Represents the current loop index, starting from 1. Very suitable for numbering list items.
    • forloop.Revcounter: Indicates the remaining number of loops. These variables can help us achieve more complex layout or style control, such as adding unique styles to the first, last, or specific position elements.
  3. Conditional judgment:{% if %}Flexible filtering.Sometimes, we may want to exclude certain pages when iterating through all single pages, or conditionally render based on a page's properties. AnQiCMS'sifLogical judgment labels can be well integrated withforcombined with loops:

    {% pageList pages %}
        {% for item in pages %}
            {# 假设我们想排除ID为5的特定单页面 #}
            {% if item.Id != 5 %}
                <h3><a href="{{ item.Link }}">{{ item.Title }}</a></h3>
                {# ... 其他内容 ... #}
            {% endif %}
        {% empty %}
            <p>目前还没有任何单页面内容发布。</p>
        {% endfor %}
    {% endpageList %}
    

Complete code example: dynamically display all service pages

Let's combine the above techniques to build a more完善的 example, dynamically displaying all service pages of the website in a sidebar:

`twig

Related articles

The `pageList` tag defaults to fetching which single page data from the website?

As an experienced website operations expert, I am well aware of the efficiency and flexibility of AnQi CMS in content management.Today, let's delve deeply into an important member of the AnQiCMS template tag system - the `pageList` tag, especially regarding which single page data it will retrieve by default.Understanding this is crucial for us to present content efficiently and design templates. --- ## Deeply analyze the Anq CMS `pageList` tag: What single page data is retrieved by default?

2025-11-07

What is the basic syntax structure of the `pageList` tag in AnQiCMS?

## Deeply analyze the basic syntax structure of the `pageList` tag in AnQi CMS Among the powerful functions of AnQi CMS, template tags play a vital role as the bridge connecting backend data with frontend display.For the common single-page content such as 'About Us', 'Contact Us', 'Terms of Service', and others on the website, Anqi CMS provides a simple and efficient tool for management and presentation, that is the `pageList` tag.

2025-11-07

How to call single page detail data of other sites in a multi-site management environment?

Good, as an experienced website operation expert, I am happy to analyze for you how to efficiently and flexibly call the single page detail data of other sites in the multi-site management environment of AnQiCMS. --- ## Secure CMS Multi-site Management: Easily Handle Cross-site Single Page Detail Data Calls In today's rapidly changing digital world, many businesses and content operations teams face the challenge of managing multiple websites.

2025-11-07

How to use the `token` (URL alias) parameter in the `pageDetail` tag?

AnQiCMS (AnQiCMS) is an efficient and flexible enterprise-level content management system that provides many conveniences in content publishing and SEO optimization.The flexible application of URL alias (`token`) parameters is crucial for enhancing the user experience and SEO-friendliness of the website.Today, let's delve deeper into how to fully utilize the `token` parameter when using the `pageDetail` tag in AnQiCMS templates.

2025-11-07

What core fields does each single page object returned by the `pageList` tag contain (such as ID, title, link)?

As an experienced website operations expert, I know that fully understanding the details of template tags in an efficient content management system like AnQiCMS is the key to fine-grained operations and content presentation.Today, let's delve into the `pageList` tag, an important tool for obtaining a single-page list, and explore the core fields and operational value contained in each single-page object (`item`).

2025-11-07

How to correctly add basic pagination tag features to the article list in AnQiCMS?

In the digital age where content is king, the website's content list carries the primary entry point for users to explore information and understand products.A well-designed, smooth experience article list can not only effectively improve the user's stay time on the website, but also help users quickly find the information they need through accurate navigation guidance.AnQiCMS (AnQiCMS) is an efficient and flexible content management system that understands this well, providing website operators with powerful and easy-to-use template tag functions, among which, adding basic pagination functions to the article list is a key factor in improving user experience and website accessibility.

2025-11-07

What is the role of the `show` parameter of the `pagination` tag? How to control the number of page numbers displayed at the bottom of the page?

As an experienced website operations expert, I know that it is crucial to effectively guide users to browse and discover information when managing a large amount of content.The pagination feature is the bridge that connects users to the deep content of the website.In AnQiCMS (AnQiCMS) such an efficient and customizable content management system, flexible use of pagination tags can greatly enhance user experience and the professionalism of the website.Today, let's delve into a core parameter of the `pagination` tag in AnQiCMS, namely `show`, and see what its role is

2025-11-07

How to customize the text content of the 'First Page', 'Previous Page', 'Next Page', 'Last Page' pagination tags in AnQiCMS templates?

As an experienced website operations expert, I am well aware of the importance of website details in user experience and brand image.AnQiCMS (AnQiCMS) with its flexible template mechanism and strong multilingual support, allows us to easily meet these customization requirements.Today, let's delve into how to precisely customize the pagination labels such as 'Home', 'Previous', 'Next', and 'Last Page' in the AnQiCMS template, making your website's pagination not only functional but also full of brand characteristics.### Understand AnQiCMS

2025-11-07