As an experienced security CMS website operator, I know that content is the soul of the website, and how to efficiently and accurately present content is a crucial part of our daily work.In AnQi CMS, a single page usually carries the core information of the company introduction, contact information, service description, etc., and its content often needs to be specifically obtained 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 Anqi CMS.

In the Anqi CMS template system, the key to obtaining specific single-page information lies in usingpageDetailThe tag is specifically designed to extract detailed data from a single page, either through its unique ID or its custom URL alias (token).

Get data from a specific single page

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

In the Anqi CMS backend, under 'Page Resources' and 'Page Management', you can find the list of all single pages created.Each single page has a system-assigned ID, and you can also set a custom URL alias for it.For example, a single-page named “About Us” may have an ID of1and 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 templatepageDetailTag to access its properties. For example, if you want to get the page information 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,aboutPageWe define the variable name for the single page data we get. Once the data is assigned to this variable, we can access it throughaboutPage.属性名Access the specific fields of the single page in the form

Display the title of the single page

After obtaining the single-page data, the title is displayed very directly. The title of a single page is usually accessed byTitlethe field.

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

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

This will display the title of the 'About Us' page in the form of a heading on your web page.

Display the content of a single page

The content of a single page is stored inContentWithin a field. Since page content usually contains HTML tags (such as paragraphs, images, links, etc.), in order to ensure that these HTML is rendered correctly by the browser rather than as plain text, we need to use|safefilter.

Additionally, if your single-page content is written using a Markdown editor and the Markdown editor feature is enabled in the background "Content Settings", 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 withrender=trueThe parameter enforces the conversion from Markdown to HTML.

The following is displayedaboutPageAn example of content:

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

Or, if you need to enforce 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 presented correctly on the page.

Display the link to a single page

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

The following is displayedaboutPageHere is an example of the 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 Example

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 displaying some of its content, we can build 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 go throughpageDetailTags, flexible to obtain and display key information of a specific single page at any location on the website.Understanding and mastering these tags can greatly enhance your efficiency in content management and template customization on Anqi CMS.


Frequently Asked Questions

What if the single page I need to access has not set a URL alias

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

Why is the HTML content of my single page displayed directly instead of being rendered?

This situation usually occurs because you haven't set up the single page correctly.ContentField usage|safeFilter. Anqi CMS, for security reasons, defaults to escaping all output variables 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 up a custom URL alias for a single page or view its ID in the background?

In the AnQi CMS backend, navigate to 'Page Resources' and then click 'Page Management'.On this page, you can see the list of all single pages created, including their IDs.Click on the 'Edit' button of any single page, after entering the edit page, you can set or modify the URL alias of the single page in the 'Custom URL' field.If not set, the system will automatically generate a default alias based on the page name.