How to display the content, title, and image of a single page in a custom page?

Calendar 👁️ 80

In website operation, we often need to create unique display methods for specific content, such as designing a unique landing page for product features, service introductions, or company profiles.AnQiCMS (AnQiCMS) with its flexible content model and highly customizable features makes everything very simple.Today, let's talk about how to easily display the content, title, and images of a custom page, making your website content more personalized.

Understanding Anqi CMS' 'Single Page'

First, we need to clarify what a 'single page' is in the Anqi CMS.In Anqi CMS, a single page refers to those pages that exist independently and do not belong to any category (such as article or product categories).They are usually used to display "About UsYou can create and edit these single pages under the 'Page Resources' and 'Page Management' in the background.Each single page has its own title, content, images, and even custom URLs and templates.

Create and associate custom templates: let the single page have exclusive display

To display single-page content on a custom page, the first step is to prepare a dedicated template file and associate it with the single-page backend.

  1. Prepare the template fileThe template files of AnQi CMS are stored in/templateIn a directory of a theme folder. You can create a new HTML file for your current website theme here, for example, we name itcustom-single-page.html.

  2. Linked to a single pageAfter you have created the template file, go to the "Page Resources" -> "Page Management" in the Anqi CMS backend to edit or create a new single page.On the single-page editing interface, you will see an option for a 'single-page template'.custom-single-page.htmlOnce saved, this single page will be rendered using the template you specified.

    Moreover, AnQi CMS also provides some default template naming conventions. For example, if you want a single page (assuming its ID is 10) to have its own template, you can directly create one namedpage/detail-10.htmlThe file, the system will automatically recognize and apply. Or if you have set a custom URL alias for the "About Us" single pageaboutyou can create onepage/about.htmlTemplate file, it can also be applied by selecting it on the backend.

Core:pageDetailThe use of tags

In your custom template file (for examplecustom-single-page.htmlIn it, we need to use the powerful template tags of Anqi CMS to obtain and display the various information of a single page. Among them,pageDetailtags are the tools to obtain the content of a single page.

pageDetailThe tag can retrieve detailed data for a single page, including title, content, description, link, and various images.

Basic usage:

You can use two main methods to do so.pageDetailUse the tag to retrieve data for a single page:

  1. Automatically fetch the current page dataIf your custom template is the same as the template associated with a single page, thenpageDetailThe label does not require additional parameters, it will automatically retrieve all information from the current page. For example:{{ page.Title }}(If the page object has been preloaded)

  2. Retrieve specific page data by specifying an ID or URL aliasIf you want to call a specific single-page content in a non-single-page template (such as the homepage or article detail page), you need to specify it by its ID or URL alias.

    • Get by ID:{% pageDetail myPage with id="123" %}(where 123 is the actual ID of the single page)
    • Get by URL alias:{% pageDetail myPage with token="about-us" %}(where "about-us" is the custom URL alias of the single page)

Once you use{% pageDetail myPage ... %}Assign single-page data to a variable (for examplemyPage), you can access its various properties through dot notation.

Get the title, content, and images:

  • Title:{{ myPage.Title }}
  • Description:{{ myPage.Description }}
  • Content:{{ myPage.Content }}
  • Logo:{{ myPage.Logo }}
  • Thumbnail (Thumb):{{ myPage.Thumb }}
  • Image Gallery (Images):{{ myPage.Images }}(This is an array, need to iterate through)

Special reminder:On the single page displayContentWhen the content contains HTML tags (such as styles generated by a rich text editor), you must use|safeFilter. This is because the Anqi CMS template engine, for security reasons, defaults to escaping all output as HTML entities to prevent XSS attacks. Add|safeThe system will inform you that this content is safe and can be rendered directly as HTML. If your content is in Markdown format and the background Markdown editor is enabled, the template will try to automatically convert it, but to ensure compatibility, it can be explicitly added|render|safefilter.

Actual Operation: Code Example and Explanation

Suppose we created acustom-single-page.htmlTemplate, and associate it with the single page with backend ID 123. Here is an example code of how to display the content of the single page in the template:

"`twig {# Assume you have a base template, such as one that includes the header, footer, and other common parts #} {% extends 'base.html' %}

{% block title %}

{# 自动获取当前页面的SEO标题,如果未设置则 fallback 到单页面标题 #}
<title>{% tdk with name="Title" siteName=true %}</title>

{% endblock %}

{% block content %}

{# 使用pageDetail标签获取ID为123的单页面所有数据,并赋值给currentPage变量 #}
{% pageDetail currentPage with id="123" %}

{% if currentPage %}
    <article class="single-page-custom-layout">
        {# 显示单页面标题 #}
        <h1>{{ currentPage.Title }}</h1>

        {# 显示单页面描述(如果存在)#}
        {% if currentPage.Description %}
            <p class="description">{{ currentPage.Description }}</p>
        {% endif %}

        {# 显示单页面主图片/Logo #}
        {% if currentPage.Logo %}
            <div class="main-image">

Related articles

How to use breadcrumb navigation tags to display the current page path at the top of the page?

In website operation, a clear navigation path is crucial for user experience and search engine optimization.When a user is browsing deep pages on a website, a straightforward 'You are here' prompt can help them quickly locate and easily return to the parent directory.This is a kind of auxiliary navigation method, which we call breadcrumb navigation.AnQiCMS (AnQiCMS) is built-in with powerful breadcrumb navigation tags, allowing developers and content operators to easily display the current location path at the top of the page.What is breadcrumb navigation and why is it important?

2025-11-09

How to display a list of friendship links on the front page of the website?

In website operation, friendship links have always been an important means to enhance website authority, increase external traffic, and enhance user trust.If you are using AnQiCMS to manage your website and want to display a list of friend links on the frontend page, you will find that this process is surprisingly simple and efficient.AnQi CMS, with its simple design and powerful features, makes content management easy, and the display of friendship links is no exception.Next, let's take a look at how to display friend links in Anqi CMS.

2025-11-09

How to customize the display of Banner Carousel images on the website homepage?

In website operation, the homepage Banner carousel image is an important component to attract visitors' attention and convey core information.AnQiCMS (AnQiCMS) understands this need and provides a flexible and convenient way for you to easily customize and display these key visual elements on the homepage of your website. ### Prepare: Manage Your Banner Image in the Background First, we need to make sure that the images used for the carousel have been uploaded and properly managed.The AnQi CMS usually provides a special "Banner Management" area in the background

2025-11-09

How can you format a timestamp to display the publication date in a friendly date and time format?

In website operation, the content publication date is not just a time mark, it is also an important basis for visitors to obtain information timeliness.A clear and readable date format that can significantly improve user experience and make your website content appear more professional and considerate.However, in a powerful content management system like AnQiCMS, the publication date is usually stored in the database in the form of a "timestamp", which is usually a string of numbers that is difficult to understand directly.For example, you might see a number like `1609470335`

2025-11-09

How to define a temporary variable in a template and use it to display content?

In Anqi CMS, when managing website content, we often find that using temporary variables flexibly in templates can make the code more concise, efficient, easy to understand, and maintainable.The Anqi CMS template system has borrowed the syntax of the Django template engine, which provides a straightforward way to define and use these temporary variables. ### Temporary variables make the template more concise and efficient Why do we need to define temporary variables in the template?

2025-11-09

How to truncate long text content in a template and add an ellipsis for display?

In website content operation, we often encounter scenarios where it is necessary to display long text, such as article abstracts, product descriptions, or user comments.If the complete content is displayed directly, it may cause the page to be long and disorganized, affecting the reading experience of the user.At this time, the long text is intelligently truncated and an ellipsis (...) is added at the end, making it an elegant and practical solution.AnQi CMS as a powerful content management system, its flexible template engine provides a variety of convenient ways to meet this need.### Efficient Core Tool for Extracting Long Text Content

2025-11-09

How to ensure that the template file uses UTF-8 encoding to avoid garbled Chinese content?

In website operation, the clear and accurate presentation of content is crucial.Especially when your website contains Chinese content, if you encounter a "garbled code" problem, it not only seriously affects the user experience, but may also damage the professional image of your website.For users of Anqi CMS, ensuring that all template files use the correct encoding, especially UTF-8, is the first step to avoid such problems and is also the most fundamental and critical guarantee.### Why is UTF-8 so important? UTF-8 is the full name of Unicode Transformation

2025-11-09

How to display a custom shutdown notice to visitors when the website is under maintenance?

As website operators, we always encounter situations where we need to maintain and upgrade the website, whether it is database optimization, system updates, or content adjustments. These operations sometimes require temporarily shutting down the website to avoid unexpected errors or incomplete content display during maintenance.However, simply displaying a "cannot open" error page on a website undoubtedly gives visitors a bad experience, and may even make search engines mistakenly believe that the website is permanently offline.AnQiCMS (AnQiCMS) fully understands this pain point and provides a graceful and flexible solution that allows you to maintain your website while it is closed for maintenance

2025-11-09