An efficient and flexible content management system, AnQi CMS provides strong support for content operation in the field.In daily website management, single-page (or independent page) plays an indispensable role. Whether it is to display corporate culture in "About UsTherefore, how to accurately and efficiently call the detailed information of these specific single-page templates in website templates has become a key skill that website operators and template developers need to master.
The template system of AnQi CMS is designed very well, drawing many advantages from Django template engine, making content calls both powerful and intuitive. If you are familiar{{变量}}English output content,{% 标签 %}Used to control the logic syntax, so calling data in the Anqi CMS will be a piece of cake.For single-page content, the system provides special tags to help us obtain and display its detailed information.
core tools:pageDetailDeep interpretation of tags
When we need to display the complete content of a specific page in the template,pageDetailThe label is our preferred tool. The function of this label is to extract all detailed data of the corresponding single page according to the identifier you provide, and make it flexible for you to use in the template.
pageDetailThe basic structure and key parameters of tags:
{% pageDetail 变量名称 with name="字段名称" id="1" %}
Here are some core points worth paying attention to:
变量名称(Optional): You can specify a variable name for the single-page information you obtain (for example,aboutPage)。指定后,你就可以通过{{aboutPage.字段名}}来调用其数据。如果省略,标签将直接输出指定name字段的值,更适用于简单、直接的调用。name="字段名称"(Optional)This parameter allows you to directly specify the specific fields of the single page to be called, such asTitle(Title),Content(Content) and others. If specified变量名称, then thisnameparameter can be omitted and called directly through the variable.id="1"ortoken="your-page-alias"(Key)This is the core method of specifying 'specific single-page'.id:Directly specify the unique number ID in the background system via a single page. For example, if the ID of "About Us" is 1, it can be usedid="1".token:Through the single-page URL alias (usually an English string, 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 have not specified
idortoken,pageDetailThe label will attempt to retrieve the detailed information of the current page (if the current page is a single page) by default.
siteId(Multi-site scenario)If you have enabled the multi-site feature of Safe CMS and need to call single-page data from other sites, you cansiteId="站点ID"specify it. Generally, there is no need to set this parameter.
pageDetailThe label can retrieve a list of fields on a single page:
The AnQi CMS stores rich field information for each single page, throughpageDetailLabels, you can easily access them:
Id: The unique numeric identifier of the single page.Title:Single-page title, usually the large title seen by users on the page.Link:Single-page access link.Description:Brief description of a single page, often used in SEO meta tags.Content:The main content of a single page, which may contain rich text or Markdown format.Logo:Single-page thumbnail large image address.Thumb:Single-page thumbnail address.Images:The slide group image of a single page, which is an array containing multiple image addresses.
How to flexibly use in the templatepageDetail?
Let's understand it specifically through several practical scenariospageDetail.
Scenario one: Displaying a brief introduction of 'About Us' in the fixed area of the sidebar or bottom
Assuming your website footer needs to display a brief introduction to the "About Us" single page, and the ID of the "About Us" single page is5, the 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 demonstrated two calling methods.If you need to reference different fields of the same page multiple times, using variables to receive complete information (Method 2) will be more concise and efficient.
Scene two: Display the complete content of a specific single page on the homepage (for example, an important announcement)
Suppose you have a single page named 'Latest Announcement' with ID is10You want 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 made use of{% if latestNotice.Images %}to determine if there is an image group, and through{% for img in latestNotice.Images %}The slideshow displays multiple slides.{{ latestNotice.Content|safe }}is a very important detail, it tells the template engine to treat the content as safe HTML and not to simply escape it. If your single-page content is entered through a Markdown editor, the CMS will usually automatically convert HTML, but to ensure accuracy or if you need to manually control the rendering behavior, you canContentField call addsrender=trueparameters, such as{{ latestNotice.Content|render:true|safe }}.
Scenario three: judge and load custom single page template according to URL alias
The Auto CMS allows you to set a custom template for specific pages (set in the "Single Page Templatepage/contact.html.
Intemplate/你的模板目录/page/create acontact.htmlFile. When you set a single page template in the background,contact.htmlvisiting the single page will automatically load this template.
Incontact.htmlTemplate inside, since this page is the single page itself, you can use it directlypageDetailTags can get 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 %}
**Practical Tips and Considerations
- Uniqueness is the key: Whether through
idOrtokenCall a specific page, please make sure the identifier you use is unique. When creating a single page in the background, the system will handle it automatically.iduniqueness,tokenThe custom URL alias needs to be manually maintained for uniqueness. - Use wisely
|safeFilterWhen a single page'sContentorDescriptionfield may contain HTML tags, please make sure to use|safefilters (for example{{ someVariable|safe }}),to prevent content from being escaped, ensure that the HTML structure is rendered correctly. - The importance of background configurationEnsure that the specific single page has been created and published in the 'Page Resources -> Page Management' section of the Anqi CMS backend before calling it in the template.At the same time, setting up its 'Custom URL' and 'Single Page Template' reasonably will provide more convenience and flexibility for your frontend display.
- Debugging and TestingIn the development process, if you find that the call does not take effect or displays an error, please first check whether the single page ID or URL alias is correct, then confirm whether the template syntax is correct, and finally check whether the content of the single page meets expectations.
By flexibly using the Anqi CMS,pageDetailTags, we can easily call and display rich information of specific single pages at any location on the website as needed, thus building a more dynamic and interactive user experience.Master this skill, and it will greatly enhance your efficiency in content operation and template development on the AnQi CMS.
Common Questions and Answers (FAQ)
Q1: If I specifypageDetailthe single page ID or URL alias in the tag does not exist, will the template report an error?
A1:In most cases, the template engine of the security CMS is designed to be robust, when you go throughpageDetailWhen a tag calls a non-existent ID or URL alias, it does not directly throw a fatal error causing the page to crash. Instead, the tag returns empty data (i.e., the value of the corresponding field will be an empty string ornil)。This means that in the template, if you try to access these fields, they will not display any content.{% if somePage.Title %}Check if the data exists, only