As an experienced website operations expert, I know that how to efficiently and accurately obtain the required data in a content management system is the key to improving operational efficiency.In AnQiCMS, a single page (or sometimes referred to as a standalone page) is commonly used to display important but not frequently changed content such as 'About Us', 'Contact Information', and 'Service Introduction'.Sometimes, we not only need to display the details on the single page itself, but may also need to refer to specific parts of the single page in other locations on the website (such as the homepage, sidebar).
Today, let's delve into a very practical feature of Anqi CMS: how to accurately obtain detailed data of a single page through the single page ID.This technique will help you organize and display website content more flexibly, even in complex scenarios of content references, with ease.
Mastering Anqi CMS Single Page: Accurately Obtain Detail Data through ID
In AutoCMS, a single page is an important component of building the website's basic structure.They usually carry corporate culture, product and service overview, contact information, and other independent and relatively fixed content.Single Page IDIt's like an ID number, it is the exclusive code of this single page. At the same time, you can also set for the single pageURL Alias (token)as a more semantic identifier.
core tools:pageDetailFlexible Use of Tags
English CMS provides a powerful and flexible template tag ——pageDetailIt is the core tool we use to achieve precise acquisition of single-page detail data.This label is designed very humanized, it can not only obtain the details of the current visited page (without additional parameters), but also can obtain the data of any specified page from any location on the website by specifying the single page ID or URL alias.
Let's take a lookpageDetailBasic usage of the tag. When you are in a single-page template file (such aspage/detail.htmlorpage/about.html) you can use it directly.{{page.Title}}or{% pageDetail with name="Title" %}Get the title of the current page. But if your need isTo accurately obtain the data of a single page with a specific IDso thatpageDetailThe power of tags is demonstrated.
Precise location: Retrieve specified page data through single page ID
Suppose you want to display a brief introduction of the "About Us" single page on the homepage of your website, and the ID of this single page is 10. In this case, you can do so in the homepage template file (usuallyindex/index.htmlorindex.html), usepageDetailLabel and pass inidThe parameter is used to accurately obtain:
{# 假设“关于我们”单页的ID是 10 #}
{# 获取ID为10的单页标题 #}
<h3>{% pageDetail with name="Title" id="10" %}</h3>
{# 获取ID为10的单页简介 #}
<p>{% pageDetail with name="Description" id="10" %}</p>
{# 获取ID为10的单页内容,并确保HTML内容安全输出 #}
<div>
{% pageDetail aboutContent with name="Content" id="10" %}
{{ aboutContent|safe }}
</div>
{# 获取ID为10的单页链接 #}
<a href="{% pageDetail with name="Link" id="10" %}">了解更多</a>
In the above example, we throughid="10"The parameter clearly states:pageDetailLabel, we need to get the single page data with ID 10. You will notice that we can also assign the obtained data to a variable (such asaboutContent),Then use this variable in subsequent templates, which not only makes the code clearer but also reduces unnecessary database queries.
It should be noted that when you retrieve a single page ofContentThe field 'auto' contains, if the content includes HTML tags, please be sure to cooperate|safeFilter usage to ensure HTML is parsed correctly rather than being escaped and displayed. If your single-page content is written using a Markdown editor in the background and you want to render it as HTML on the frontend, you can also add extrarender=trueParameter, for example: {% pageDetail aboutContent with name="Content" id="10" render=true %}.
In addition to the single-page ID, you can also use the single-page URL alias (token) to make the call, which will be very convenient when you are unsure of the specific ID but know the alias:
{# 假设“联系我们”单页的URL别名是 "contact-us" #}
<h4>联系方式:{% pageDetail with name="Title" token="contact-us" %}</h4>
Single page detail fields available for calling
pageDetailTags support retrieving various properties of a single page, you can throughnameThe parameter specifies the required fields. The following are some commonly used callable fields, covering all aspects of single-page content management:
Id: The unique numeric identifier of the single page.Title: The title of the single page.Link:Single-page access link.Description:Single-page introduction or description information.Content:Main content of the single page, may include HTML or Markdown format.Logo:Single-page thumbnail large image address.Thumb:Single-page thumbnail address.Images:Single-page slideshow or group image, usually an array of image URLs, which needs to befora loop to iterate and display.
For example, if you want to display all slide images on a single page:
{% pageDetail pageBannerImages with name="Images" id="15" %}
<div class="banner-carousel">
{% for imgUrl in pageBannerImages %}
<img src="{{ imgUrl }}" alt="单页图片" />
{% endfor %}
</div>
Summary and **Practice
PasspageDetailTags and precise single-page ID or URL alias, you can flexibly obtain and display detailed data of any single page in the Anqi CMS.This provides great convenience for the reuse and dynamic display of website content.
In actual operation, I suggest you:
- Use ID first: For internal references and backend configurations, the single page ID is the most stable and accurate identifier.
- Use URL AliasesIn some scenarios, using aliases can improve code readability, especially in team collaboration or code handover.
- Note the content format:According to the actual storage format of the single-page content (plain text, HTML, Markdown), use it reasonably.
|safeorrender=trueParameters to ensure the correct rendering of the content. - Gracefully handle empty data.In case of obtaining image, list, and other possible empty data, it can be used with
{% if ... %}to make a judgment, to avoid errors or blank pages on the page.
Master these skills, and you'll be able to better utilize the content management capabilities of Anqi CMS, creating a richer and more attractive content experience for your website.
Common Questions (FAQ)
1. I use it directly in the template{{page.Title}}Why do I need to learn if I can get the titlepageDetailTags?
{{page.Title}}This form is usually only available on the page you are currently visitingisThat is valid only for single-page, it depends on the current page context.pageDetailThe power of tags is that you canany page, by explicitly specifyingidortokenparameters, and accurately obtainAny specified single pageDetails data. For example, you need to display the summary of the "About Us" page on the homepage, at this time{{page.Title}}It is not possible to obtain the title of the "About Us" page, and you will need to use it{% pageDetail with name="Title" id="关于我们页面的ID" %}.
2. My single-page content is written in Markdown on the backend, why does the front-end display the Markdown source code instead of the rendered HTML?
This is usually because you have notpageDetailLabel the specified Markdown rendering parameters. If your CMS backend has enabled the Markdown editor and the single-page content is written in Markdown, then through the front end,pageDetailGet content requires additional parameters.render=trueParameters are required so that the system converts them to HTML before outputting. For example:{% pageDetail singlePageContent with name="Content" id="123" render=true %}{{ singlePageContent|safe }}{% endpageDetail %}.
**3. If the single page ID I specify does not exist, the page will generate an error.