How to get and display the detailed content and Banner image of a single page in the AnQiCMS template?

Calendar 👁️ 64

In Anqi CMS, to retrieve and display the detailed content of a specific single page and its associated Banner image, it mainly involves understanding the management method of single pages and mastering the flexible application of template tags.AnQiCMS provides an intuitive backend management interface and a powerful template engine, making this task simple and efficient.

Deeply understand the single-page in Anqi CMS

The 'Single Page' feature of AnQi CMS is designed for pages with a fixed structure, relatively independent content, and no frequent updates, such as 'About Us', 'Contact Information', 'Service Introduction', and so on.In the background, you can create and edit these single pages under 'Page Resources'.Banner image.

It is worth noting that AnQiCMS also allows you to specify a unique template file for a single page. By default, the content of a single page will usepage/detail.htmlThe template is rendered. But if you need a specific single page (such as the "About Us" page with ID 5) to have a completely different layout, you can createpage/detail-5.htmlFor example, even in the "Single Page Template" field in the backgroundabout_us.htmlThen place the file intemplate/您的模板目录/page/Under the path. This flexibility allows each single page to have a highly customized display effect.

Get the detailed content of a single page.

In the template, the 'core tool' to get the content of a single page ispageDetailthe tag. This tag can help you pull various information from the specified single page.

To get the content of the single page you are currently visiting, you do not need to specify any ID or alias,pageDetailTags will be automatically recognized:

{# 假设您正在访问ID为1的“关于我们”页面 #}

{# 获取单页面标题 #}
<h1>{% pageDetail with name="Title" %}</h1>

{# 获取单页面描述 #}
<p>{% pageDetail with name="Description" %}</p>

{# 获取单页面内容,需要注意安全输出 #}
<div class="page-content">
    {% pageDetail pageContent with name="Content" %}
    {{ pageContent|safe }}
</div>

Key points explanation:

  • with name="字段名称"This is the parameter that specifies which specific field content you want to obtain. For example,"Title"Get the title,"Description"Get the description,"Content"Get the main content.
  • pageContent with name="Content": We will assign the single-page content we obtain to a variable namedpageContent. The benefit of doing this is that you can{% pageDetail ... %}Outside the tag, use this variable multiple times or in a more flexible way.
  • {{ pageContent|safe }}This point is very important!The "content" field on a single page typically contains HTML code generated by a rich text editor.|safeFilter. If you forget to use it, the HTML tags on the page will be displayed directly, causing style confusion.

If you need to retrievenot the current pagespecific single page content, you can achieve this by specifying its ID or a custom URL alias(token)

{# 获取ID为2的单页面的标题 #}
<h2>{% pageDetail with name="Title" id="2" %}</h2>

{# 获取自定义URL别名为“contact-us”的单页面内容 #}
<div class="contact-info">
    {% pageDetail contactPageContent with name="Content" token="contact-us" %}
    {{ contactPageContent|safe }}
</div>

Display the Banner image of a single page

The single page of AnQi CMS supports uploading multiple Banner images. These images can also be retrieved through tags and displayed in a loop.pageDetailTags can be used to retrieve these images and display them in a loop.

pageDetailThere is a tag namedImagesThe field, it will return an array containing all the uploaded Banner image URLs.

{# 假设您正在访问的单页面上传了多张Banner图 #}
<div class="page-banner-slider">
    {% pageDetail pageBanners with name="Images" %}
    {% if pageBanners %} {# 检查是否有Banner图上传 #}
        {% for imageUrl in pageBanners %}
        <div class="banner-item">
            <img src="{{ imageUrl }}" alt="单页面Banner" />
        </div>
        {% endfor %}
    {% else %}
        {# 如果没有上传Banner图,可以显示一个默认图片或者不显示 #}
        <img src="/static/images/default_banner.jpg" alt="默认Banner" />
    {% endif %}
</div>

Tips for getting the first Banner image:

In some designs, you may only need to display the first Banner image uploaded on a single page. In this case, you can directly access the first element of the array:

<div class="page-header-banner" style="background-image: url('{% pageDetail firstBanner with name="Images" %}{% if firstBanner %}{{ firstBanner[0] }}{% endif %}');">
    {# 这里可以放置标题等内容 #}
    <h1>{% pageDetail with name="Title" %}</h1>
</div>

In this example, we first attempt to retrieveImagesfield and assign it tofirstBannervariable. Then, by{% if firstBanner %}{{ firstBanner[0] }}{% endif %}to ensure that it outputs the URL of the first elementfirstBannerwhen the array exists and is not empty.

Combine an example: Build a complete single-page display template

Assuming we have a single-page "About Us", with ID 5, in HTML format, and multiple Banner images uploaded. Here is a simplified template snippet showing how to combine these tags:

`twig {% extends ‘base.html’ %} {# Inherit base layout template #}

{% block title %}

<title>{% tdk with name="Title" siteName=true %}</title>
<meta name="keywords" content="{% tdk with name="Keywords" %}">
<meta name="description" content="{% tdk with name="Description" %}">

{% endblock %}

{% block content %}

<div class="container">
    {# 面包屑导航,让用户了解当前位置 #}
    {% breadcrumb crumbs %}
    <ul class="breadcrumb">
        {% for item in crumbs %}
            <li><a href="{{ item.Link }}">{{ item.Name }}</a></li>
        {% endfor %}
    </ul>
    {% endbreadcrumb %}

    {# 单页面Banner区域 #}
    <div class="page-banner-area">
        {% pageDetail pageBanners with name="Images" id="5" %} {# 获取ID为5的单页面Banner图 #}
        {% if pageBanners %}
            <div class="owl-carousel owl-theme"> {# 假设您使用Owl Carousel来展示轮播图 #}
                {% for imageUrl in pageBanners %}
                <div class="item">
                    <img src="{{ imageUrl }}" alt="关于我们Banner" class="img-fluid"/>
                </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="default-banner">
                <img src="/public/static/images/default_about_banner.jpg" alt="默认关于我们Banner" class="img-fluid"/>
            </div>

Related articles

How to display all single page lists on AnQiCMS template?

In website operation, we often need to create some independent pages, such as "About Us", "Contact Information", "Terms of Service", or some special introduction pages.These pages are usually called "single-page", their content is fixed, they do not belong to the conventional article or product categories, but they are an indispensable part of the website.When you have accumulated a large number of single pages on your website, you may wish to display a list of these single pages in a specific location, such as the bottom of the website, the sidebar, or even on a dedicated page, to facilitate browsing and searching for visitors.

2025-11-07

How to retrieve and display detailed information about a category, such as the category title, description, and thumbnail, in AnQiCMS?

In AnQi CMS, obtaining and displaying detailed information of a category is an indispensable part of building a dynamic website. Whether it is used to create a category list, a category special page, or display the information of the category in the article detail page, AnQi CMS provides simple and powerful template tags to achieve this. <h3>Deeply understand the `categoryDetail` tag</h3> AnQi CMS template system adopts a syntax similar to Django, where `categoryDetail`

2025-11-07

How to display all articles under a specific category in the AnQiCMS template?

When building a website with AnQiCMS, we often need to make the page content more flexible to meet the display needs of different blocks.One of the most common needs is how to accurately display a list of all articles under a specific category in the template.AnQiCMS with its efficient architecture based on the Go language and similar Django template engine syntax makes this task both intuitive and powerful.

2025-11-07

How to display the breadcrumb navigation path of the current page in AnQiCMS template?

In website operation, a clear navigation path is crucial for user experience.Breadcrumb Navigation is like a clue in real life, clearly showing the user's current position on the website, allowing them to easily see where they are and quickly return to the previous or higher-level page.This not only helps users quickly understand the website structure and improve user experience, but also greatly benefits search engine optimization (SEO), as it helps search engines better understand the hierarchical structure of the website. AnQiCMS

2025-11-07

How to display the friend link list in the admin panel of the AnQiCMS website?

On the AnQiCMS website, the display of the background management friends link list is a very practical feature. It not only helps to enhance the website's SEO effect, but also provides more valuable external resources for visitors.AnQiCMS provides a simple and efficient mechanism for managing and displaying these links, allowing even beginners to get started easily.

2025-11-07

How to format the article publish timestamp into a readable date and time in AnQiCMS template?

In website content operation, the publication time of articles is often one of the focuses of users, as it not only affects the interest of users in reading but also has a potential impact on the timeliness and authority of the content.However, the time information stored in the database is usually in a machine-readable timestamp format, such as a series of numbers, which is difficult for ordinary visitors to understand.AnQiCMS fully considered this point, providing a flexible way for you to convert these timestamps into clear and easy-to-read date and time formats, greatly enhancing the user experience.

2025-11-07

How to display custom field content (such as author, source) in AnQiCMS templates?

AnQiCMS with its flexible content model and powerful template tag system provides great convenience for personalized display of website content.In website operations, we often need to add some information outside of standard fields for articles, products, or other content, such as the author of the article, source of content, product batch number, or specific SEO information.This non-standardized information, AnQiCMS calls it 'custom fields', they can make your website content more professional, detailed, and meet specific business needs.

2025-11-07

How to implement lazy loading of image content in AnQiCMS templates to optimize performance?

In the digital age, the speed of website access has become one of the key indicators for measuring user experience and search engine rankings.Images are an important part of web page content and often also a major factor affecting page loading speed.When a page contains a large number of high-definition images, the browser needs to load all image resources before rendering the page, which undoubtedly greatly increases the user's waiting time.This problem was solved by the emergence of lazy loading (Lazy Loading) technology.The core idea of lazy loading images is to delay loading images that are not within the current viewport (i.e., the visible area of the user's current screen)

2025-11-07