AnQi CMS, as an efficient and flexible content management system, has provided strong support for us in the field of content operation.In daily website management, single pages (or independent pages) play an indispensable role, whether it is to display corporate culture on "About Us", provide a communication bridge with "Contact Us", or introduce various service pages, they are all important windows for users to obtain core information.Therefore, how to accurately and efficiently call the detailed information of these specific single-page templates has become a key skill that website operators and template developers need to master.
The AnQi CMS template system is designed very well, it draws on many advantages of the Django template engine, making content calls both powerful and intuitive. If you are familiar with{{变量}}Used for output content,{% 标签 %}The syntax for controlling logic, so calling data in Anqi CMS will be an easy task.For such single-page content, the system provides special tags to help us retrieve and display its details.
Core tool:pageDetailIn-depth interpretation of tags
When we need to display the complete content of a specific single page in the template,pageDetailThe tag is our preferred tool. The role of this tag is to extract all detailed data from the corresponding single page according to the identification you provide, and to make it flexible for use in the template.
pageDetailThe basic structure and key parameters of the tag:
{% pageDetail 变量名称 with name="字段名称" id="1" %}
Here are some core points that we should pay attention to:
变量名称(Optional): You can specify a variable name for the single page information you get, for example:aboutPage)。After specifying, you can call its data through{{aboutPage.字段名}}to call its data. If omitted, the label will directly output the specifiednamefield value, more suitable for simple, direct calls.name="字段名称"(Optional)This parameter allows you to directly specify the specific field of the single page to be called, such asTitle(Title),Content(Content) etc. If specified变量名称, then thisnameparameter can be omitted and called directly through the variableid="1"ortoken="your-page-alias"(Key)This is the core way to specify a 'specific single page'.id: Directly specify the unique numeric ID of the page in the background system. For example, if the 'About Us' ID is 1, you can useid="1".tokenThrough a single-page URL alias (usually a string of English characters, such as "about-us") to specify.This is a more readable and SEO-friendly way. When creating a single-page in the background, you can customize this URL alias.- If you do not specify
idortoken,pageDetailThe tag will try to get the details of the current page by default (if the current page is a single page).
siteId(Multi-site scenario)If you have enabled the multi-site feature of Anqicms CMS and need to call single-page data from other sites, you cansiteId="站点ID"specify this. Generally, there is no need to set this parameter.
pageDetailA list of fields that can be obtained from a single page:
Anq CMS stores rich field information for each single page, through:pageDetailTags, you can easily access them:
Id: The unique numerical identifier of a single page.Title: The title of a single page, usually the large title seen by the user on the page.Link: The access link of a single page.Description: A brief description of a single page, often used in SEO meta tags.Content: The main content of a single page, which may include rich text or Markdown format.Logo: Thumbnail large image address of a single page.Thumb: Thumbnail address of a single page.Images: Slide group image of a single page, this is an array containing multiple image addresses.
How to use templates flexiblypageDetail?
Let's get to know by some actual scenariospageDetailusage.
Scenario one: Display the 'About Us' introduction in the fixed area of the sidebar or bottom
Assuming your website footer needs to display a brief introduction to the "About Us" page, and the "About Us" page's ID is5the URL alias isabout-us.
{# 方法一:通过ID直接调用简介 #}
<div class="footer-about">
<h4>关于我们</h4>
<p>{% pageDetail with name="Description" id="5" %}</p>
<a href="{% pageDetail with name="Link" id="5" %}">了解更多</a>
</div>
{# 方法二:通过URL别名指定,并用变量接收完整信息 #}
{% pageDetail aboutUs with token="about-us" %}
<div class="footer-about">
<h4>{{ aboutUs.Title }}</h4>
<p>{{ aboutUs.Description }}</p>
<a href="{{ aboutUs.Link }}">了解更多</a>
</div>
{% endpageDetail %}
In the above example, we have demonstrated two calling methods.If you need to refer to different fields of the same page multiple times, using variables to receive complete information (method two) will be more concise and efficient.
Scenario two: Display the full content of a specific single page on the homepage (for example, an important announcement)
Assuming you have a single page named 'Latest Announcement' with ID is10,You hope to display the complete content in a specific area on the homepage.
{% pageDetail latestNotice with id="10" %}
<section class="latest-announcement">
<h2>{{ latestNotice.Title }}</h2>
<div class="notice-content">
{# 注意:Content字段可能包含HTML内容,需要使用 |safe 过滤器确保正确渲染,而非转义 #}
{# 如果后台开启了Markdown编辑器且内容是Markdown,系统会自动转换,但手动 render=true 更明确 #}
{{ latestNotice.Content|safe }}
</div>
{% if latestNotice.Images %}
<div class="notice-images">
{% for img in latestNotice.Images %}
<img src="{{ img }}" alt="{{ latestNotice.Title }} 图片" />
{% endfor %}
</div>
{% endif %}
<p><a href="{{ latestNotice.Link }}">查看完整公告</a></p>
</section>
{% endpageDetail %}
Here we not only called the title and content, but also used{% if latestNotice.Images %}to determine if there is a picture group, and through{% for img in latestNotice.Images %}The loop displayed multiple slide images.{{ latestNotice.Content|safe }}It is a very important detail that tells the template engine to treat the content as safe HTML rather than simply escaping it. If your single-page content is entered through a Markdown editor, Anqi CMS will usually automatically convert HTML, but if you want to ensure accuracy or need to manually control the rendering behavior, you canContentField is added when calledrender=trueparameters, for example{{ latestNotice.Content|render:true|safe }}.
Scenario three: Load a custom single-page template based on URL alias
AnQi CMS allows you to set a custom template for specific single pages (set "Single Page Template" in the background single page management), for example, to create a custom template for the "Contact Us" pagepage/contact.htmltemplate for exclusive use.
Intemplate/你的模板目录/page/Create a folder undercontact.htmlFile. When you set a single page template in the backgroundcontact.htmlthe single page will automatically load this template.
Incontact.htmlWithin the template, since the current page is this single page, you can use it directlypageDetailThe tag retrieves the details of the current single page without specifyingidortoken:
{# page/contact.html 模板文件内容示例 #}
{% pageDetail currentPage with name="Title" %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>{{ currentPage.Title }} - {% system with name="SiteName" %}</title>
</head>
<body>
<header>
<h1>{{ currentPage.Title }}</h1>
</header>
<main>
<p>{{ currentPage.Description }}</p>
<div class="contact-info">
{{ currentPage.Content|safe }}
</div>
</main>
<footer>
{# 调用系统设置中的联系方式 #}
<p>电话: {% contact with name="Cellphone" %}</p>
<p>邮箱: {% contact with name="Email" %}</p>
</footer>
</body>
</html>
{% endpageDetail %}
**Practice and Precautions
- Uniqueness is crucialWhether through
idOrtokenCall a specific single-page, be sure to ensure that the identifier you use is unique. When creating a single-page in the background, the system will automatically handle itiduniqueness, andtoken(Custom URL alias) must be manually maintained unique. - Make good use of
|safeFilter: When single page of theContentorDescriptionfield may contain HTML tags, please be sure to use|safefor example, a filter (such as{{ someVariable|safe }}To prevent content from being escaped, ensure that the HTML structure is rendered correctly. - The importance of backend configurationBefore calling the specific page information in the template, make sure that the page has been created and published in the "Page Resources -> Page Management" section of the Anqi CMS backend.At the same time, reasonably setting its "custom URL" and "single-page template" will provide more convenience and flexibility for your front-end display.
- Debugging and testingIn the development process, if you find that the call does not work or displays an error, please first check if the single-page ID or URL alias is correct, then confirm if the template syntax is incorrect, and finally check if the single-page content meets expectations.
By flexibly using AnQi CMS'spageDetailThe label allows us to easily call and display rich information of a specific single-page at any location on the website, thus building a more dynamic and interactive user experience.Mastering this skill will greatly enhance your efficiency in content operation and template development for Anqi CMS.
Frequently Asked Questions (FAQ)
Q1: If I ampageDetailDoes the template report an error if the single page ID or URL alias specified in the tag does not exist?
A1:Generally, the template engine of Anqi CMS is designed to be quite robust, when you go throughpageDetailWhen a tag calls an ID or URL alias that does not exist, it will not directly throw a fatal error causing the page to crash. Instead, the tag will return empty data (i.e., the value of the corresponding field will be an empty string ornilThis means that if you try to access these fields in the template, they will not display any content.In order to provide a better user experience, you can use conditional judgments in the template (such as{% if somePage.Title %}Check if the data exists, only