As an experienced CMS website operation personnel for security, I know that content is the soul of the website, and how to display content efficiently and accurately is a crucial part of our daily work.In the AnQi CMS, a single page usually carries the core information such as company introduction, contact information, and service description. The content often needs to be specifically retrieved and displayed in various corners of the website.Today, let's delve into how to retrieve and display the title, content, and link of a specific single page in the Anqi CMS.

In the template system of AnQi CMS, the key to obtaining specific single-page information lies in usingpageDetailLabel. This label is specifically designed to extract detailed data from a single page, whether through its unique ID or its custom URL alias (token).

Get data for a specific single page

To get data for a specific single page, we first need to know the unique identifier of the page, which is usually the page ID or a custom URL alias (token) set in the background.

In the "Page Resources" under "Page Management" on the AnQi CMS backend, you can find the list of all single pages created.Each single page has an ID automatically assigned by the system, and you can also set a custom URL alias for it.1,while its URL alias may be set toabout-us.

Once the ID or URL alias of the target single page is determined, we can use it in the templatepageDetailLabel to get its various properties. For example, if you want to get the information of the page with ID1, you can use the tag like this:

{% pageDetail aboutPage with id="1" %}
    {# 在这里可以使用 aboutPage 变量来访问该单页面的各项属性 #}
{% endpageDetail %}

Or, if you know its URL alias isabout-usIt can be used like this:

{% pageDetail aboutPage with token="about-us" %}
    {# 在这里可以使用 aboutPage 变量来访问该单页面的各项属性 #}
{% endpageDetail %}

In the above example,aboutPageis the variable name defined for the single-page data we have obtained. Once the data is assigned to this variable, we can access it throughaboutPage.属性名The form to access specific fields of a single page, such as title, content, link, etc.

Display the title of a single page

Obtained after the single-page data is displayed, the title is very direct. The title of a single page is usually accessed throughTitlefield.

The following is how to display it in the templateaboutPageThe example of the single page title represented by the variable:

<h1>{{ aboutPage.Title }}</h1>

This will display the title 'About Us' of the single page in the form of a first-level title on your webpage.

Display the content of the single page

Content stored on a single pageContentField in. Since the page content usually contains HTML tags (such as paragraphs, images, links, etc.), in order to ensure that these HTML can be rendered correctly by the browser instead of being displayed as plain text, we need to use|safeFilter.

Moreover, if your single-page content is written using a Markdown editor, and the Markdown editor feature is enabled in the "Content Settings" backend, the system will automatically convert it to HTML. If the Markdown editor is turned off, but the content itself is in Markdown format, you can callContentthe field.render=trueParameters, force the Markdown to HTML conversion.

The following is displayedaboutPageContent examples:

<div class="page-content">
    {{ aboutPage.Content|safe }}
</div>

Or, if you need to force the rendering of Markdown content:

<div class="page-content">
    {% pageDetail pageContent with name="Content" id="1" render=true %}
    {{ pageContent|safe }}
</div>

This will ensure that the content of a single page, including all its formats and elements, is displayed correctly on the page.

Show link to a single page

To retrieve and display the link of a single page, we can accessLinkthe field. This field will directly provide the complete accessible URL of the single page.

The following is displayedaboutPageHere is an example of a link:

<p>访问我们的页面:<a href="{{ aboutPage.Link }}">{{ aboutPage.Title }}</a></p>

This will generate a hyperlink on the page that points to the single page, with the text content being the title of the page.

Comprehensive Application Examples

Combine all the steps above, assuming we need to display the title of a specific single page in a sidebar, and provide an area that jumps to the page when clicked, while also displaying some of its content, we can construct the template code in this way:

<aside class="sidebar-info">
    {% pageDetail contactPage with token="contact-us" %} {# 假设“联系我们”单页面的token是contact-us #}
        <h2>{{ contactPage.Title }}</h2>
        <p>{{ contactPage.Description }}</p> {# 可以选择显示描述而非完整内容 #}
        <a href="{{ contactPage.Link }}" class="btn-more">了解更多</a>
    {% endpageDetail %}
</aside>

This example shows how to getpageDetailLabel, flexibly obtain and display key information of a specific single page at any location on the website.Understand and master these tags, which can greatly enhance your efficiency in content management and template customization in the Anqi CMS.


Frequently Asked Questions

What if the single page I need to get does not set a URL alias?

If a single page does not have a custom URL alias set, you can still use its unique ID to retrieve information.In the "Page Management" list of the Anqi CMS backend, each single page will display an ID.pageDetailthe label useid="单页面ID"to specify the page to be retrieved, for example{% pageDetail myPage with id="5" %}.

Why is the HTML tag displayed directly instead of being rendered in the single-page content I show?

This situation usually occurs because you haven't set up the single-pageContentfield usage|safeFilter. For security reasons, AnQi CMS defaults to escaping all output variables as HTML to prevent XSS attacks. IfContentThe field contains valid HTML code, you need to add|safeThe filter informs the system that this content is safe and can be rendered as HTML, for example{{ myPage.Content|safe }}.

How to set a custom URL alias for a single page in the background or view its ID?

In the AnQi CMS backend, navigate to 'Page Resources' and then click 'Page Management'.On this page, you can see the list of all created single pages, including their IDs.Click on the "EditIf not set, the system will automatically generate a default alias based on the page name in English.