How to get the ID of the current single page in the template and display its title with the `pageDetail` tag?

Calendar 👁️ 87

As an experienced AnQi CMS website operations personnel, I know the core position of content in the website, as well as the importance of template making in the effective presentation of content. When we need to accurately obtain and display the ID and title of the current page in a single-page detail template, AnQiCMS provides an intuitive and efficient template tagpageDetailTo complete this task.

Get the current page ID and title in the AnQiCMS template.

In the AnQiCMS template system,pageDetailThe tag is a key tool used specifically for handling single-page detail data acquisition.It allows us to flexibly extract various information from the current or specified single-page, including its unique identifier ID and user-readable title.

Understand the AnQiCMS template andpageDetailTag

AnQiCMS template engine uses a tagging syntax similar to Django, separating content and logic, making it easy for website maintenance and style customization. In the template file, variables are enclosed in double curly braces{{变量}}Definition, while logical control labels (such as conditional judgment, loop) use single curly brackets and percent signs{% 标签 %}.

pageDetailThis is a powerful logical label, mainly used in the context of single-page detail pages, or by explicitly specifying an ID to obtain detailed data for a single page. When you are in a single-page detail template (such aspage/detail.htmlorpage.htmlUsed inpageDetailWhen the tag is used, it intelligently identifies the single page being accessed and extracts the required data without needing to specify an ID.

Get the ID of the current single page

To get the current page ID, we can directly use it in the single page detail templatepageDetailthe tag and use it.namethe parameter toId. BecausepageDetailThe label has the ability to automatically identify the current page in a single-page detail page, so we usually do not need to provideidParameter.

For example, in yourpage/detail.htmlIn the template file, you can get the ID of the current page like this:

<p>当前单页面ID:{% pageDetail with name="Id" %}</p>

This code will directly output the numeric ID of the current page.

Display the title of the current page

Similar to obtaining an ID, to display the title of the current single page, we also usepageDetailtags, but this time we willnamethe parameter toTitle. This ensures that we are getting the formal title configured for the single page in the background.

In the same single page detail template, the code to display the title will be:

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

This will display the title of the current single page in the form of an H1 tag.

Practice Operation: Implement in the Template

In AnQiCMS, the detail template of a single page is usually located in the directory of the template theme you are currently using.page/detail.htmlorpage.htmlFile. To clearly demonstrate how to obtain the ID and title in these templates, we can combine them.

Here is a specific template code example that displays its ID and title on a single page:

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>{% pageDetail with name="Title" %} - {% system with name="SiteName" %}</title>
</head>
<body>
    <header>
        <nav>
            {# 导航栏内容 #}
        </nav>
    </header>

    <main>
        <section>
            {# 使用pageDetail标签直接输出当前单页面的ID和标题 #}
            <h1>当前页面标题:{% pageDetail with name="Title" %}</h1>
            <p>当前页面ID:{% pageDetail with name="Id" %}</p>

            {# 也可以将ID和标题存储到变量中,方便在模板其他位置复用 #}
            {% pageDetail currentPageId with name="Id" %}
            {% pageDetail currentPageTitle with name="Title" %}
            
            <div class="page-info">
                页面ID(来自变量):{{ currentPageId }}
                <br>
                页面标题(来自变量):{{ currentPageTitle }}
            </div>

            <article>
                <h2>页面内容</h2>
                {# 显示单页面的内容,需要使用safe过滤器以避免HTML转义 #}
                <div>{% pageDetail with name="Content" %}{{ pageDetail.Content|safe }}</div>
            </article>
        </section>
    </main>

    <footer>
        {# 页脚内容 #}
    </footer>
</body>
</html>

In this example, we first in<title>within the tag usingpageDetailto get the title and then through{% system with name="SiteName" %}Retrieve the website name as the suffix of the title. Then, in the main body of the page, we use{% pageDetail with name="Title" %}and{% pageDetail with name="Id" %}Directly output the title and ID. To demonstrate variable reuse, we also show how to assign them tocurrentPageIdandcurrentPageTitleVariables are used later. Finally, it also shows how to display the content of a single page.

Extended Application: Retrieve information about other single-page applications.

pageDetailThe power of tags is not limited to ID and Title. By changingnamethe parameters, you can also obtain other rich information on a single page, such as:

  • Single page link:{% pageDetail with name="Link" %}
  • Single page description:{% pageDetail with name="Description" %}
  • Single page content:{% pageDetail with name="Content" %}(Note, often need to be accompanied by|safefilter to render HTML correctly)
  • Single-page thumbnail:{% pageDetail with name="Thumb" %}
  • Single-page slide group image:{% pageDetail pageImages with name="Images" %}{% for img in pageImages %}<img src="{{ img }}" />{% endfor %}

If you need to get information that is not the current single-page information, you can go throughidortokenThe parameter explicitly specifies the target single page. For example, to get the title of the "About Us" page with ID 5, even if you are not currently on that page, you can use{% pageDetail with name="Title" id="5" %}.

By combining these flexible tags and parameters, AnQiCMS makes template creation more efficient and customizable, ensuring that the website content is presented in the exact way you expect.


Frequently Asked Questions (FAQ)

Ask: How to get the ID and title of a specific single-page template (such as the homepage or list page)?

Answer:pageDetailTags support throughidortokenParameters to specify the single page to query. For example, if you want to display the title of the "Contact Us" single page with ID 8 on the home page of the website, you can use{% pageDetail with name="Title" id="8" %}. If you know its URL alias (for exampleabout-us), you can also use{% pageDetail with name="Title" token="about-us" %}to get the title.

Question:pageDetailWhat fields can be retrieved for a single page besides ID and Title?

Answer:pageDetailThe tag is very flexible, based onnameThe parameters differ, except for the ID (Id) and the title (Title),you can also get the link to a single page (Link), description (Description),complete content (Content),thumbnail large image (Logo),and thumbnail (Thumb) as well as a slide set diagram(Images) and other rich information. When obtaining such fields asContentwhich may contain HTML tags|safeit is usually recommended to use a filter to ensure that the content is rendered correctly.

Ask: If I use a single-page detail template andpageDetailthe current URL is not a valid single-page detail page, what will happen?

Answer: IfpageDetailThe tag is called in a non-single page detail page and does not passidortokenThe parameter explicitly specifies the page, it may not be able to obtain valid single page context information. In this case,pageDetailThe field attempted to be retrieved (such as ID or Title) may output as a blank value. To avoid this, make sure to call the template inpageDetailAt the moment, either the current URL indeed points to a single-page detail, oridortokenthe parameter provides a clear single-page identifier.

Related articles

When the website is closed (in shutdown status), can the single page be accessed normally or display a specific prompt?

In the operation practice of Anqi CMS websites, the shutdown (i.e., entering the shutdown state) is a critical step that requires careful handling.When a website needs to temporarily stop providing services due to maintenance, upgrades, or content adjustments, it is crucial to correctly set the shutdown status and display appropriate prompt information, which is important for maintaining user experience and search engine friendliness. ### Overview of the shutdown feature of Anqi CMS Anqi CMS is built with powerful global function settings, including management of the website's operational status.

2025-11-06

Does the single-page support integration with third-party comment systems?

The AnQi CMS offers a powerful and flexible solution in content management, committed to meeting the diverse needs of users.This question of whether the single-page supports integration with third-party comment systems can be explored from two perspectives: the built-in functions of AnQiCMS and the flexibility of its template system.The AnQiCMS system itself indeed has a comprehensive comment management feature.

2025-11-06

How to configure the backup and recovery strategy for a single page?

As an experienced CMS website operation person in the security field, I am well aware of the importance of data security for any website, especially for single-page content carrying key information.Under the architecture of AnQi CMS, the content, layout, media files, and related configurations of a single page all constitute an indispensable part of the website.Therefore, configuring a comprehensive backup and recovery strategy is the cornerstone of ensuring the continuous stable operation of a website and dealing with various risks (such as accidental operations, server failures, malicious attacks, etc.).Although AnQi CMS mentioned "resource storage and backup management" in the project advantages

2025-11-06

Does AnQi CMS support content scheduling for page management?

As a website operator who deeply understands the operation of AnQiCMS, I understand your emphasis on content publishing efficiency and strategy.In response to your question about whether the Anqi CMS page management function supports scheduled content publishing, I can provide you with a detailed explanation.The Anqi CMS has fully considered the flexibility and automation requirements of content publishing in its core functional design.By thoroughly analyzing the provided documents, we can confirm that Anqi CMS indeed has the ability to schedule content publishing, but its application scope needs to be treated specifically.

2025-11-06

How does the `render` parameter in the `pageDetail` tag control the conversion of Markdown content?

As an experienced website operator who deeply understands the operation of Anq CMS, I know the impact of content presentation on user experience and the professionalism of the website.In daily content management, we often encounter scenarios where we need to flexibly control content conversion, especially for content written in Markdown format.The Aanqi CMS provides fine-grained control, where the `render` parameter of the `pageDetail` tag is the key.

2025-11-06

How to retrieve and loop to display the title of single-page content (`ContentTitles`) through template tags?

As an experienced security CMS website operation personnel, I fully understand the importance of content organization and user experience in attracting and retaining users.When dealing with long articles or complex content, it is crucial to clearly present the structure of the content, such as through a dynamically generated table of contents, which is essential for improving user reading efficiency and the SEO performance of the website.Anqi CMS provides a very convenient template tag to help us achieve this goal.

2025-11-06

How to operate the AnQiCMS multi-site management function?

As a website operator who deeply understands the operation of AnQiCMS, I know the importance of efficient management of multiple sites for corporate brand building and content operation.The multi-site management function of AnQiCMS is specifically designed to meet this need, allowing you to manage multiple independently operated websites under a single system architecture, whether it is a brand sub-site, a multi-language site, or a content branch, it can be easily handled.Now, let's delve into the specific operational process of the AnQiCMS multi-site management feature.

2025-11-06

How to use AnQiCMS custom content model to meet specific business needs?

As a senior CMS website operator, I fully understand the core role of the content management system in business development.A flexible and customizable content management system that can help us efficiently deal with various business scenarios and meet the ever-changing needs of readers.In AnQiCMS, the content model is a powerful tool to achieve this flexibility.The content model is one of the core features of AnQiCMS, allowing us to create a completely personalized content structure based on specific business scenarios and content types.

2025-11-06