In AnQi CMS, whether it is to display corporate profiles such as 'About Us' or static content such as 'Contact Information', 'Terms of Service', the single-page function is very practical.It allows you to create independent pages that do not belong to any category, and provides a flexible way to control the display of these pages.
To make the AnQi CMS display the single-page content of a specified ID, you will mainly use the built-in template tags and the page management function of the backend.This makes it very convenient to customize exclusive layouts at any location on the website or for specific single-page customization.
1. Understand the single page feature of Anqi CMS
The single-page design of Anqi CMS aims to manage those content that are relatively fixed and exist independently.For example, a company's 'About Us' page usually includes a company profile, development history, corporate culture, etc. This content is not updated or categorized into a specific column as frequently as articles or products, but it is an indispensable part of the website.
The AQ CMS provides a special management entry for these single pages, allowing you to easily create, edit, and publish these pages in the background, and fine-tune their titles, content, SEO information, even the display templates.
2. ThroughpageDetailTag precise call single page content
In the template system of Anqi CMS,pageDetailThis is a key tag used to obtain detailed information of a single page.This tag is very powerful, you can use it to call its content in any template file of the website (such as the homepage, sidebar, article detail page, etc.), based on the single page ID or its custom URL alias (token).
For example, you want to display the summary of the "About Us" single page in the sidebar of the website homepage. Assuming you know the ID of the "About Us" single page is5You can write code in the template like this:
{# 假设“关于我们”单页面的ID是5,pageDetail标签将获取该单页的所有信息,并赋值给pageData变量 #}
{% pageDetail pageData with id="5" %}
{# 在调用之前,最好检查一下pageData是否存在,避免因ID错误导致页面报错 #}
{% if pageData %}
<div class="sidebar-about-us">
<h3><a href="{{ pageData.Link }}">{{ pageData.Title }}</a></h3>
<p>{{ pageData.Description }}</p>
{# 如果想显示单页面的完整内容的一部分,通常需要使用过滤器来截取文本,例如: #}
{# <p>{{ pageData.Content|striptags|truncatechars:100 }}</p> #}
<a href="{{ pageData.Link }}" class="more-link">了解更多</a>
</div>
{% endif %}
{% endpageDetail %}
In this piece of code:
{% pageDetail pageData with id="5" %}: is the core part. It tells the system to look for the ID of5The single-page, and assign all available fields (such as title, link, description, content, etc.) topageDatathis variable.{{ pageData.Title }}/{{ pageData.Description }}/{{ pageData.Link }}These are the callspageDatato specific fields in the variable.{% if pageData %}This is a good habit to judge whether the single page data is successfully obtained, to avoid errors when the data does not exist.
If you want to display the content itself directly in a single-page template file (for example, when the user clicks on the "About Us" link in the navigation bar), since the system already knows that the current page is this single page, you do not need to specify an ID and can directly call:
{# 这是“关于我们”单页面的专属模板文件,比如可能位于 /template/您的主题/page/about.html #}
{% pageDetail pageContent %}
<h1>{{ pageContent.Title }}</h1>
<div class="main-content">
{# **注意:** 单页面内容通常包含HTML富文本,为了正确显示HTML结构,务必使用 `|safe` 过滤器。 #}
{{ pageContent.Content|safe }}
</div>
{% if pageContent.Images %}
<div class="gallery">
{% for image_url in pageContent.Images %}
<img src="{{ image_url }}" alt="{{ pageContent.Title }}">
{% endfor %}
</div>
{% endif %}
{% endpageDetail %}
3. For specifying a single page, customize an exclusive template.
The single-page feature of Anqi CMS not only supports calling through ID but also allows you to specify a dedicated template file for a specific single page, realizing a more personalized display effect.This is very useful for pages like "About Us" and "Contact Us" that require a unique layout.
The general steps are as follows:
Create or edit a single page in the background:
- Log in to the CMS backend, go to "Page Resources" and then "Page Management."
- Create a new page or edit an existing page, such as "About Us."
- Find the field 'Single Page Template' in the form editor on the page.
- Here, you can enter a custom template filename, such as
about.html. The system will load the specified template first when accessing this single page according to this setting.
Prepare to customize the template file:
- According to the template agreement of Anqi CMS, the template files of a single page are usually stored in the theme directory.
page/folder. - For example, if your theme name is
defaultand you set the 'About Us' single page template in the background.about.htmlthen you need to/template/default/page/directory to create a file namedabout.htmlthe file. - in this
about.htmlIn the file, you can use the way as described in the above “Display content in the single-page self-template”,pageDetailto obtain and display page data with tags.
- According to the template agreement of Anqi CMS, the template files of a single page are usually stored in the theme directory.
The advantage of this method is that you don't have to hardcode IDs at each reference to a single page. Instead, the display method is determined by the page URL itself and the backend template settings, greatly improving management efficiency and the reusability of templates. Moreover, you can also set a "custom URL" for single pages in the backend to make the access address more semantically meaningful, for example, setting the URL for "About Us" as/about-us.html.
Through the above two methods, whether it is to flexibly call the specified ID of a single page information in other pages, or to design a unique display template for a specific single page, Anqi CMS provides a clear and easy-to-use solution to help you easily manage the static content of your website.
Common Questions (FAQ)
Q1: I created a 'About Us' single page and wrote the content, but when accessing the front-end, the content is not displayed completely or HTML tags are displayed. What's the matter?A1: This is very likely because you did not use it when displaying single-page content in the template.|safeFilter.The content of a single page is typically rich text, containing HTML tags.In the template system of AnQi CMS, to prevent potential security issues (such as XSS attacks), all content retrieved from the database is automatically escaped by default, which means HTML tags will be displayed as plain text.{{ pageContent.Content }}) to add.|safeFilters such as{{ pageContent.Content|safe }}This will inform the system that the content is safe and can be parsed and displayed as HTML.
Q2: How do I add a 'About Us' link to the navigation bar of the website?A2: You can configure it in the "Backend Settings" -> "Navigation Settings" on the Anqi CMS backend.Select the navigation category you need to edit (such as "Top Navigation"), and then add a new navigation link.In 'Link Type', select 'Category Page Link', then find and select the 'About Us' single page you created from the list.The system will automatically generate the correct link address for you.
Q3: Can I use different layouts for different single-page websites (for example, the "About UsOf course you can.The "Single Page Template" feature is provided by Anqi CMS to achieve this.about.htmlContact us specified ascontact.htmlThen, how does your current topictemplate/your_theme/page/Under the directory, create these corresponding template files, and design their unique layouts in each file.So, when the user accesses these single pages, the system will load the specified template for each one, realizing different page layouts.