How to determine if a single page exists in the template and display its content?

Calendar 👁️ 67

As an experienced security CMS website operation personnel, I know that it is crucial to flexibly control the display of content in template development, especially for single-page content such as "About Us" and "Contact Us" that may require dynamic judgment and display.In actual operation, we often need to decide whether to render a block or link based on the existence of a page, in order to ensure the accuracy of website content and user experience.Below, I will elaborate on how to determine if a single page exists in the Anqi CMS template and display its content.

Judging the existence and display of a single page in the Anqi CMS template

AnQi CMS provides simple and efficient template tags, allowing content developers to easily judge and render various dynamic content on the front-end template.For the management and display of single pages (Page), the system has designed special tags to enable us to conveniently implement the existence detection and content output of specific single pages.

Understand the single-page structure of AnQi CMS

Firstly, we need to understand the basic features of the single page in Anqi CMS.Under the 'Page Resources' module in the background, we can create and manage various single-page applications, such as company profile, service projects, contact information, and so on.Each single page has a unique ID and can be set to a "custom URL" (also known as Token).At the same time, we can also specify a "single page template" for the single page, which means that different single pages can have independent display styles.In the template system, the default template path for a single page is usuallypage/detail.htmlAlso can be for a specific ID or custom URLpage/detail-{单页ID}.htmlorpage/{自定义URL}.html.

Determine if the single page exists

We can use Anq CMS to determine whether a single page exists in the template,pageDetailThe tag can not only be used to obtain detailed information of a single page, but its design also allows its results to be assigned to a variable for subsequent logical judgment.

To implement existence judgment, we can try to retrieve page data through the ID of a single page or its custom URL (Token) and store it in a temporary variable.If the variable is successfully assigned a page object, it means that the single page exists;On the contrary, if the variable is empty, it means the single page does not exist.

For example, if we want to determine whether the single page with ID5exists, and store the result inmySinglePagevariable, we can write the code like this:

{% pageDetail mySinglePage with id="5" %}

Or, if the custom URL of a single page is knownabout-us, then you can use:

{% pageDetail mySinglePage with token="about-us" %}

After that, we can useifLogical judgment tags to checkmySinglePageWhether the variable contains valid data:

{% if mySinglePage %}
    {# 此处表示单页面存在,可以显示其内容 #}
{% else %}
    {# 此处表示单页面不存在,可以显示备用内容或不显示任何内容 #}
{% endif %}

Display the content of a single page

Once the single page exists, we can access the properties of the single page through the previously assignedmySinglePagevariable and display its content.pageDetailThe tag retrieves the page object that includes commonly used fields such as title, content, link, and description.

The following are some ways to access commonly used fields:

  • Page ID:{{ mySinglePage.Id }}
  • Page title:{{ mySinglePage.Title }}
  • Page link:{{ mySinglePage.Link }}
  • Page Description:{{ mySinglePage.Description }}
  • Page content:{{ mySinglePage.Content|safe }}(Note)|safeFilter to prevent HTML content from being escaped
  • Page thumbnail full image:{{ mySinglePage.Logo }}
  • Page thumbnail:{{ mySinglePage.Thumb }}

For the page contentContentfield, if the background enables the Markdown editor, the content will be automatically converted to HTML. If manual control is needed, you can do so bypageDetailthe tag withrender=trueorrender=falseThe parameter forces Markdown conversion or not.

Comprehensive example

Assuming we want to display a "About Us" link in the website footer, and if the "Contact Us" page exists, then display its title and some content, otherwise display a default contact information.

Backend configuration:

  • Create an ID for5a single page with a custom URL asabout-us, titled “About Us”, and fill in the content.
  • Create an ID for6a single page with a custom URL ascontact-usContact us title, and fill in the content containing HTML or Markdown.

Template code example:

<div class="footer-links">
    <h3>快速链接</h3>
    <ul>
        {# 显示“关于我们”页面链接 #}
        {% pageDetail aboutPage with id="5" %}
        {% if aboutPage %}
            <li><a href="{{ aboutPage.Link }}">{{ aboutPage.Title }}</a></li>
        {% endif %}

        {# 判断“联系我们”页面是否存在并显示其内容 #}
        {% pageDetail contactPage with token="contact-us" %}
        {% if contactPage %}
            <li>
                <h4>{{ contactPage.Title }}</h4>
                <p>{{ contactPage.Description }}</p>
                {# 显示部分内容,注意使用|safe过滤器 #}
                <div class="contact-excerpt">{{ contactPage.Content|truncatechars_html:150|safe }}</div>
                <a href="{{ contactPage.Link }}">查看详情</a>
            </li>
        {% else %}
            <li>
                <h4>联系我们</h4>
                <p>电话: {% contact with name="Cellphone" %}</p>
                <p>邮箱: {% contact with name="Email" %}</p>
                <p>地址: {% contact with name="Address" %}</p>
            </li>
        {% endif %}
    </ul>
</div>

By using the above method, we can flexibly determine the existence of a single page in the Anqi CMS template and dynamically display its content as needed.This makes the website template more robust and intelligent, able to better adapt to the changes in content management requirements.


Frequently Asked Questions (FAQ)

1. Can I only determine if it exists by the ID of a single page or a custom URL?

Yes, in Anqi CMS template tags,pageDetailTags mainly throughid(Page ID) ortoken(Custom URL alias) to accurately find a specific single page. These parameters are the most direct and effective ways to identify and retrieve a single page.

2. How to ensure that HTML tags in the single page content are displayed correctly and not escaped into plain text?

When you output from the templatepageDetailcontent obtained from the tag (for example{{ mySinglePage.Content }}) To ensure that the HTML tags within the content are parsed and rendered by the browser, you need to use|safea filter. For example:{{ mySinglePage.Content|safe }}This is the default HTML escaping mechanism implemented by AnQi CMS for security considerations,|safeThe filter explicitly informs the system that this content is safe and does not require escaping.

3. How can I display all published single page lists in a block and only show their titles and links?

You can usepageListTag to get the list of all single pages. This tag will return all pages as an array object, you can iterate over this array to display the title and link of each page. For example:

<ul>
{% pageList allPages %}
    {% for page in allPages %}
    <li><a href="{{ page.Link }}">{{ page.Title }}</a></li>
    {% endfor %}
{% endpageList %}
</ul>

In this way, you can dynamically display all the available single-page navigation or list on the website.

Related articles

How to retrieve the list of all single pages using the `pageList` tag and display it on the front end?

As a senior person who is deeply familiar with AnQiCMS (AnQiCMS) operation, I know that content is the core position in website construction.The single page acts as the cornerstone for carrying corporate core information, service introduction, contact information, and other static content. Its effective display is crucial for users to understand the website and the corporate image.This article will elaborate on how to use the built-in `pageList` tag of AnQiCMS to retrieve and flexibly display all single page content on the frontend.### Master the `pageList` tag to build a clear single-page navigation and display In AnQiCMS

2025-11-06

`pageDetail` tag can call which detailed information of a single page (such as ID, title, content)?

As an experienced enterprise CMS website operation person, I know that efficient content management is crucial for the success of the website.The single page is an important part of the website architecture, carrying core static information such as 'About Us', 'Contact Information', and 'Terms of Service'.The Anqi CMS provides a powerful `pageDetail` tag, allowing operators to flexibly call and display various detailed information on a single page.The `pageDetail` tag is a data call tool designed specifically for single-page content in the Anqi CMS template engine

2025-11-06

What happens if the specified single-page template file does not exist?

In AnQi CMS, the single-page template file plays a crucial role, responsible for defining the layout and style of independent pages such as 'About Us' and 'Contact Information'.Website operators usually specify specific template files for these single pages according to business needs to achieve personalized content display.However, if the specified single-page template file does not exist, it will directly affect the normal access and user experience of the page.

2025-11-06

How to specify an independent template file for a single page?

As a senior CMS website operation personnel in an enterprise, I know that the flexibility of content display is crucial for attracting and retaining users.The AnQi CMS provides powerful template customization capabilities, allowing us to specify independent template files for different page features, thereby achieving personalized content layout and design.This is particularly important for creating unique single-page websites, such as 'About Us', 'Contact Information', or specific event landing pages.Understanding AnQi CMS template mechanism All template files in AnQi CMS are stored uniformly in

2025-11-06

How to use the lazy loading feature of images in single page content?

As an experienced AnQiCMS website operator, I know the importance of website performance for user experience and SEO.Lazy loading of images is an essential optimization method to improve website loading speed, especially on single-page content that contains a large number of images.AnQiCMS provides good support for lazy loading of images at the content rendering level, allowing us to implement this feature through simple template configuration combined with front-end technology. I will elaborate in detail on how to implement lazy loading of images in the single-page content of AnQiCMS.

2025-11-06

How to obtain the SEO title and description of a single page through template tags?

As an experienced security CMS website operator, I am well aware of the key role that each page plays in search engine optimization, especially the SEO title and description.They are not only the first line of defense to attract users to click, but also an important signal to convey the core content of the page to search engines.AnQi CMS is well-versed in this, providing us with powerful and flexible template tags, allowing us to precisely control the SEO elements of each single page.

2025-11-06

How to correctly call the `Link` single page link in the template?

As an experienced security CMS website operator, I know that correctly calling content links in templates is crucial for website user experience and search engine optimization.The single page is a key part that carries static information such as 'About Us' and 'Contact Information', and the accurate calling of its links is an indispensable part of daily operation. I will elaborate in detail on how to correctly call single-page links in the Anqi CMS template.### Understanding Single Page Links in AnQi CMS In AnQi CMS, a single page (also known as a "page") exists independently of content models such as articles, products, and the like.

2025-11-06

Can the creation time or update time of a single page be retrieved and displayed?

In the operation practice of Anqi CMS, we often pay attention to the time information of the release and update of website content.This is crucial for search engine optimization (SEO) and for users to understand the timeliness of content.Whether the creation time or update time of a single page (Page) can be obtained and displayed, a detailed analysis based on the document provided by Anqi CMS can lead to a clear conclusion.The 'Page Management' feature of AnQi CMS is mainly used to create and manage independent static content pages, such as 'About Us', 'Contact Information', etc.

2025-11-06