How to get and display the content and title of a specific single page in AnQiCMS?

Calendar 👁️ 65

In AnQiCMS, single pages are a very practical part of the website structure, and they are usually used to display static content such as 'About Us', 'Contact Information', etc.As a content operator, you may often need to retrieve and display the content and titles of specific single pages at different locations on the website.AnQiCMS provides intuitive and powerful template tags, making this process very simple.

Understanding the single page in AnQiCMS

One of AnQiCMS's design philosophies is the high degree of customizability of content.The single page is managed in the "Page Resources" module on the backend. You can set a separate title, content, keywords, description, even a custom URL, and a dedicated template file for each single page.This flexibility allows a single page to not only carry rich information but also perfectly integrate with the overall design style of the website.

In the AnQiCMS template system, you will find that it uses a syntax similar to the Django template engine, using double curly braces{{变量}}Output variables, while conditional judgments and loop controls are used{% 标签 %}Structure. All template files are recommended to use UTF-8 encoding to avoid garbled characters.

The core tool to retrieve the content and title of a specific single page:pageDetailTag

To retrieve and display the content and title of a specific single page, we mainly use:pageDetailThis template tag. This tag is specifically designed to extract detailed information from a single page.

pageDetailThe basic usage of tags is:{% pageDetail 变量名称 with name="字段名称" id="页面ID" %}.

Here变量名称is an optional parameter, if you set it, you can call the data obtained through this variable. If omitted变量名称,pageDetailthe label will output the specifiednamefield value.nameThe parameter is used to specify the specific field you want to retrieve, whileidortokenThe parameter is used to specify which single page.

To get the title of a single page

To display the title of a single page, you need tonameSpecify in the parameterTitleFor example, if you want to get the title of the single page you are currently visiting, you can write it like this:

<h1>{% pageDetail with name="Title" %}</h1>

If you want to get the title of a single page with ID 10, regardless of which page you are currently on, you can do it like this:

<p>这是ID为10的单页面标题:{% pageDetail with name="Title" id="10" %}</p>

You can also specify a single page using its URL alias, i.e.tokenSpecify a page. This is very useful when you want to reference a page with a more descriptive URL. For example, if your "About Us" page's URL alias is set toabout-usYou can get the title like this:

<p>关于我们页面的标题是:{% pageDetail with name="Title" token="about-us" %}</p>

Get the content of a single page

Getting the main content of a single page is also simple, just need tonamethe parameter toContentIt is. It should be noted that the content of a single page usually contains HTML tags, in order for the browser to parse and display these formats correctly, you need to cooperate with|safefilter usage.|safeThe filter tells the template engine that this part of the content is safe HTML and does not need to be escaped.

If you have enabled the Markdown editor to edit single-page content in the background and want to render it as HTML on the front end, you can add in theContentfield.render=trueparameters:

<div>
    {% pageDetail pageContent with name="Content" render=true %}
    {{ pageContent|safe }}
</div>

If your content is not Markdown or you do not want Markdown renderingrenderThe parameter can be omitted.

This is an example of fetching the current single page content:

<section class="page-content">
    {% pageDetail contentData with name="Content" %}
    {{ contentData|safe }}
</section>

Actual application example: Display the title and introduction of the "Contact Us" single page in the sidebar

Suppose you have a 'Contact Us' single page with ID 5, and you want to display its title and part of the content (summary) in the website sidebar.

<aside class="sidebar-contact">
    <h2>{% pageDetail with name="Title" id="5" %}</h2>
    <p>{% pageDetail with name="Description" id="5" %}</p>
    <a href="{% pageDetail with name="Link" id="5" %}" class="btn-more">了解更多</a>
</aside>

In this example, we specifyid="5"to obtain the title of a specific single page (Title), description (Description) and the links(Link), and display them in the sidebar.

Tips and **Practice

  1. Make good use of|safeFilterWhen you display any content that may contain HTML (such as single-page content, article content), be sure to use|safeFilter, otherwise HTML tags may be displayed as plain text.
  2. Custom URL alias improves SEO: Set meaningful custom URL aliases for single-page pages (tokenIt not only facilitates memory and reference, but also helps to improve search engine optimization.
  3. Naming conventions of template files:AnQiCMS supports custom templates for specific single pages. For example, you can createtemplate/your_template_folder/page/about.htmlFile, and specify the use of this template for the "About Us" page in the "Page Management" section of the background. This can achieve more detailed page layout control.
  4. Background managementIn the "Page Resources" -> "Page Management" section, you can conveniently create, edit, and manage all single pages.Here the "page name

By flexible applicationpageDetailTags and related parameters, you will be able to easily handle the single-page content display of AnQiCMS, whether it is building a standard corporate website or a complex marketing site, you will be able to handle it with ease.

Frequently Asked Questions (FAQ)

1. Why is my single-page content displaying raw HTML code instead of formatted content?This is likely because you did not use|safeFilter.The AnQiCMS template engine, for security reasons, defaults to escaping all output content to prevent XSS attacks.|safeFilter, for example{{ pageContent|safe }}.

2. How do I reference and display the title of a specific single page in the sidebar of the article detail page?You can use in the template of the article detail page,pageDetailLabel and specify a single pageidortokenFor example, if you want to display the title of the 'Contact Us' page with ID 5, you can write it like this:<h3>{% pageDetail with name="Title" id="5" %}</h3>This will display the title of the specified single page regardless of the current article.

3. If I want to use a completely different layout for a specific single page instead of the default onepage/detail.htmlHow should I operate?AnQiCMS supports custom templates for each single page. You can create a new template file in your template folder (for exampletemplate/default), such aspage/custom-about.htmlThen, edit the single page in the background "Page Management", find the "Single Page Template" setting, and fill incustom-about.htmlAnd so, the single page will use the custom layout you created.

Related articles

How to display the list and links of all single pages in AnQiCMS template?

In AnQiCMS, wanting to display a list and links of all single pages in a website template is actually a very common requirement, such as you may want to place a 'site map' or 'quick link' area at the bottom of the website, or you may need to list all 'service items' single pages in the sidebar.AnQiCMS provides a simple and powerful template tag that allows you to easily achieve this.### Understanding Single Page and Its Role In AnQiCMS, a single page (Page) is usually used to publish content that is relatively fixed

2025-11-08

How to display detailed information and description of the current category in AnQiCMS?

When operating the AnQiCMS website, we often need to dynamically display detailed information and descriptions of the current category on the category page, such as the title, introduction, large picture, and even custom fields.This not only helps users better understand the theme of the current page, but also effectively improves the page's SEO performance.The Anqi CMS provides very flexible and intuitive template tags, making this task easy and simple.### Get to know the `categoryDetail` tag

2025-11-08

How to get the category list of a specified content model and display it in AnQiCMS?

In AnQiCMS, flexibly obtaining and displaying the category list of the specified content model is the key to building a clear website structure and a good user experience.Whether it is product display, article archive, or service introduction, the category list plays an important navigation role.AnQiCMS's powerful template tag system makes this process intuitive and efficient.

2025-11-08

How to use the breadcrumb navigation tag of AnQiCMS to display the current page path?

In website operation, a clear navigation path is crucial for user experience and search engine optimization (SEO).A Breadcrumb Navigation is an auxiliary tool that can significantly improve the usability of a website, providing a quick and convenient way for users to return to their previous page and clearly indicating their position on the current page.In AnQiCMS, implementing breadcrumb navigation is very simple and flexible.AnQiCMS provides us with a dedicated breadcrumb navigation tag `breadcrumb`, through it

2025-11-08

How to retrieve a list of articles or products in AnQiCMS and support pagination display?

How to efficiently display articles or product lists in a content management system and provide users with a smooth pagination experience is a common concern for website operators.AnQiCMS is a system developed based on the Go language, which makes everything intuitive and efficient through its flexible and powerful template tag system.Next, we will discuss how to take advantage of the built-in features of AnQiCMS to easily implement the list display and pagination functions of articles or products.

2025-11-08

How to display the detailed content of a specified article or product in AnQiCMS?

AnQiCMS (AnQiCMS) is an efficient and flexible content management system that provides an intuitive way to manage and display various types of content.When you want to display a specific article, product details, or any independent content page created through a content model on a website, the core lies in using its powerful template tag features.AnQiCMS refers to the articles, products, and other independently displayed content on the website as 'documents' (archive).

2025-11-08

How to display the previous and next article links of the current article in AnQiCMS template?

In content operation, providing navigation to the previous and next articles for each article can not only significantly improve the user's reading experience, but also effectively increase the internal links of the website, which is of great benefit to search engine optimization (SEO).AnQi CMS with its flexible template system makes the implementation of this feature intuitive and efficient.By using a short template tag, you can easily integrate this practical navigation mechanism on the article detail page.

2025-11-08

How to display related article recommendations on the AnQiCMS article detail page?

In website operation, the related article recommendation function on the article detail page can not only effectively improve the user's browsing depth within the site, reduce the bounce rate, but also guide users to discover more valuable content, indirectly improving the overall SEO performance of the website.AnQiCMS as a content management system that focuses on efficiency and scalability, provides flexible template tags, making it intuitive and convenient to implement this function. Let's discuss together how to elegantly implement related article recommendations on the article detail page of AnQiCMS.

2025-11-08