In-depth analysis of AnQiCMSpageListThe basic syntax structure of tags
In the powerful feature set of AnQi CMS, template tags play a crucial role, acting as the bridge between backend data and frontend display. For common single-page content in websites such as "About UspageListLabel. As an experienced website operations expert, I know how important it is to convert complex technical concepts into practical methods that are easy to understand, so today we will delve into this topic together.pageListLabel basic syntax structure and its flexible application in content operation.
pageListLabel: Easily get a single-page list
Anqi CMS is committed to providing an intuitive content management experience,pageListThe label is the embodiment of this concept.Its core function is to help us easily obtain all single page (Page) content of the website backend management in the template.Imagine that your website has multiple independent pages that need to be displayed in a navigation menu, footer, or specific block, manually writing the code one by one is time-consuming and prone to errors.pageListYou can dynamically pull these page data, greatly enhancing the flexibility and maintainability of the template.
Overview of basic syntax structure
pageListThe syntax structure of the label is very intuitive and easy to understand, mainly consisting of a start tag and an end tag, with code blocks in between for looping through and displaying page data. Its basic form is as follows:
{% pageList 变量名称 %}
{# 在这里循环遍历每个单页面数据 #}
{% endpageList %}
Here,变量名称is a placeholder that you define, it represents a collection containing all the single-page data (usually an array or slice). For example, we commonly usepagesAs for this variable name, the label becomes{% pageList pages %}. Once defined, you can use{% pageList ... %}and{% endpageList %}to use loop statements (such asforloop) to access each onepagesEach single-page object in the collection, and extract its specific information.
Parameters with flexible customization
Compared to some more complex list tags,pageListThe design concept of the label is to obtain 'all' single pages, therefore it does not provide direct parameters such as 'filter by category' or 'limit by quantity'. However, it still considers the needs of multi-site management and provides asiteIdParameters:
siteIdThis parameter allows you to specify which single-page data of a site to retrieve. In the multi-site management scenario of AnQi CMS, if you need to call a single-page of another site in a template of a certain site, you can do so bysiteId="指定站点ID"To implement. For most single-site operators, this parameter is usually not required, as the system will automatically obtain the single-page of the current site.
For example, if you want to get all single pages of the site with ID 2, you can write it like this:
{% pageList pages with siteId="2" %}
{# 遍历 ID 为 2 的站点的单页面 #}
{% endpageList %}
However, evenpageListThe system does not have built-in rich filtering parameters, but we can still achieve more refined content display by combining logic judgment capabilities provided by the security CMS template engine within the tags.
DeepenpageList内部:可用的页面数据字段
Once we have passed through{% pageList pages %}获取到单页面集合并开始循环遍历(例如使用{% for item in pages %}),每个item变量就代表了一个独立的单页面对象。这个itemThe object contains detailed attributes of the single page, and we can directly access them through dot notation. The following are some commonly used single-page data fields:item.属性名)to access them. The following are some commonly used single-page data fields:
item.Id: English page identifier ID, usually used for backend management or frontend unique link construction.item.Title: English page title, which is the content most often displayed to users.item.Link: Single page access link address, used directly in the template to build<a>Tagshrefproperties.item.Description: Brief description of the single page, which can be displayed in lists, cards, or SEO metadata.item.Content: Detailed content of a single page, usually the main content edited by a rich text editor. When outputting, in order to avoid the escape of HTML tags causing the content to be displayed abnormally, you need to use|safeFilter, for example{{ item.Content|safe }}.item.Logo: English: 单页面的缩略图大图地址,如果设置了的话。item.Thumb: English: 单页面的缩略图地址,通常是经过裁剪或压缩的小图。
实用场景:如何运用pageListtags
Now, let's look at several specific examples, and seepageListhow tags play a role in the actual operation of a website.
Scenario one: Building a universal footer navigation
Many websites' footers list links to common single-page sections such as “About Us”, “Contact Us”, “Privacy Policy”, and others. UsingpageListit can be easily achieved:
<nav class="footer-nav">
<ul>
{% pageList footerPages %}
{% for item in footerPages %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endfor %}
{% endpageList %}
</ul>
</nav>
This code will traverse all single pages and generate a list with titles and links.
Scenario two: Exclude a list of specific single pages.
Suppose you have a "site mappageListThere is no direct exclusion parameter, but we can make use ofifLogical judgment is performed in the loop to filter:
<nav class="sidebar-pages">
<h3>我们的页面</h3>
<ul>
{% pageList sidePages %}
{% for item in sidePages %}
{# 假设“网站地图”页面的ID是5,我们想排除它 #}
{% if item.Id != 5 %}
<li><a href="{{ item.Link }}">{{ item.Title }}</a></li>
{% endif %}
{% endfor %}
{% endpageList %}
</ul>
</nav>
With simple condition judgment, we can flexibly control which pages will be displayed.
Scene three: Display a single-page summary with thumbnails
If some of your single pages (such as "Team Introduction" or "Case Studies") are configured with thumbnails and summaries, you can usepageListCreate a list with visual elements:
<div class="page-highlights">
{% pageList featuredPages %}
{% for item in featuredPages %}
<div class="page-card">
{% if item.Thumb %}
<img src="{{ item.Thumb }}" alt="{{ item.Title }}" class="page-thumbnail">
{% endif %}
<h4><a href="{{ item.Link }}">{{ item.Title }}</a></h4>
<p>{{ item.Description }}</p>
<a href="{{ item.Link }}" class="read-more">了解更多</a>
</div>
{% endfor %}
{% endpageList %}
</div>
Here we check:item.ThumbDoes it exist to avoid broken image links on pages without thumbnails and to display the page title, summary, and link.
Summary
pageListLabels in AnQi CMS are the core tools for managing and displaying single-page content.It allows website operators and developers to efficiently build various page navigation and content modules with its concise syntax and support for multi-site environments.Although its own parameters are not many, combined with the powerful logic processing ability of the AnQi CMS template engine, it can easily achieve various customized content display requirements.pageListThe use of, undoubtedly will bring more flexible content management and a smoother user experience to your website.
Common Questions and Answers (FAQ)
1.pageListDoes the tag support direct sorting by page title?
pageListThe tag itself does not provide directorderParameters to sort the page list.The single page of Anqi CMS usually sorts by the default sorting value or ID set in the background.If you need a specific sorting method, such as alphabetical order by title or reverse chronological order by publication time, this usually requires adjusting the sorting priority of a single page in the backend management interface, or considering secondary sorting through front-end JavaScript after obtaining the data (which will increase client load).
2. Can I likearchiveListThe same, correctpageListShould the single-page content obtained be displayed with pagination?
根据安企CMS的设计,pageListThe purpose of the tag is to get all single-page content, not designed for pagination. Therefore, it does not providetype="page"This pagination mode, also cannot be directly withpaginationThe label is combined. If you have a very large number of single-page applications and need pagination display, it is recommended that you reconsider whether this part of the content is more suitable for management as article or product model category, thereby utilizingarchiveListandpaginationThe powerful pagination feature of the label.
3. Is there a convenient method to get a single page of specific IDs instead of all pages?
pageListThe tag will default to fetching all single pages. If you only want to display specific pages, the most common method is to use a condition judgment inside the loop.pageListthe loop using conditional judgment (ifAn example of how to filter using a statement. For instance, you can define a list containing the required page IDs and then check each loop to see if it is in this list. Although it is not as direct asitem.Idwhether it is in this list. Although it is not as direct asid="1,2,3"The parameter is intuitive, but this method is still very flexible and effective.