As an experienced website operation expert, I know that how to efficiently and accurately obtain the required data in a content management system is the key to improving operation efficiency.In AnQiCMS (AnQiCMS), single pages (also known as independent pages) are often used to display "About Us", "Contact Information", "Service Introduction", and other content that does not change often but is crucial.Sometimes, we not only need to display the details on the single page itself, but may also need to reference part of the specific single page information in other places on the website (such as the homepage, sidebar).
Today, let's delve deeply into a very practical feature of Anqi CMS: how to accurately obtain the detailed data of a single page through its page ID.This technique will help you organize and display website content more flexibly, even when facing complex content citation scenarios, you can handle it with ease.
Master Anqi CMS single page: Accurately obtain details through ID
In Anqi CMS, the single page is an important component in building the website's basic structure.They usually carry corporate culture, product service overview, contact information, and other independent and relatively fixed content.Each page created in the background is assigned a unique numeric identifier—Single page IDLike an ID number, it is a unique code for this page. At the same time, you can also set it for the single pageURL alias (token)As a more semantically meaningful identifier.
Core tool:pageDetailFlexible use of tags
AnQi CMS provides a powerful and flexible template tag -pageDetailIt is the core tool we use to achieve accurate retrieval of single-page detail data.This tag is designed to be very user-friendly, it can not only obtain the single page details of the current visited page (without additional parameters), but also retrieve the data of any specified single page from any location on the website by specifying the single page ID or URL alias.
Let's take a look atpageDetailBasic 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" %}To get the title of the current page. But if your need isTo get the data of a specific ID page accuratelythenpageDetailThe power of tags is demonstrated here.
Accurate positioning: Retrieve specific page data through single page ID
Assuming you want to display a brief introduction to the 'About Us' page on the home page of your website, and the ID of the 'About Us' page is 10. In this case, you can do so in the home page template file (usually index/index.htmlorindex.htmlUse it inpageDetailLabel and pass in.idParameter 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 haveid="10"Parameter explicitly state:pageDetailLabel, we need to get the single page data with ID 10. You will notice that in order to better organize the code and avoid repeated calls, we can also assign the obtained data to a variable such asaboutContent),and 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 ofContent(Content) field, if the content contains HTML tags, please cooperate accordingly|safeThe filter is used to ensure that HTML is parsed correctly and not displayed as escaped. If your single-page content is written in the background using a Markdown editor and you want to render it as HTML on the front end, you can add extrarender=truefor 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 is very convenient when you are not sure of the specific ID but know the alias:
{# 假设“联系我们”单页的URL别名是 "contact-us" #}
<h4>联系方式:{% pageDetail with name="Title" token="contact-us" %}</h4>
Page details can be called fields overview
pageDetailTags support obtaining various properties of a single page, you cannameSpecify the required fields. The following are some commonly used callable fields that cover all aspects of single-page content management:
Id: The unique numerical identifier of a single page.Title: Title of the single page.Link: The access link of a single page.Description: Brief introduction or description information of the single page.ContentThe main content of a single page, which may contain HTML or Markdown format.Logo: Thumbnail large image address of a single page.Thumb: Thumbnail address of a single page.ImagesA single page of slides or a group of images, usually an array of image URLs, which needs to beforLoop to traverse and display.
For example, if you want to display all the 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
BypageDetailThe label and the precise single-page ID or URL alias, you can flexibly obtain and display detailed data of any single page in the Anqi CMS.This greatly facilitates the reuse and dynamic display of web 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.
- Make good use of URL aliases.In some scenarios, using aliases can improve code readability, especially in team collaboration or code handover.
- Pay attention to the content format.: Use the actual storage format of the single-page content (plain text, HTML, Markdown) appropriately
|safeorrender=trueParameters to ensure correct rendering - Gracefully handle empty data: When retrieving images, lists, and other data that may be empty, you can cooperate
{% if ... %}to make a judgment to avoid errors or blank pages on the page.
Master these skills and you will be able to better utilize the Anqi CMS content management capabilities, creating a richer and more attractive content experience for your website.
Frequently Asked Questions (FAQ)
1. I use it directly in the template{{page.Title}}I can also get the title, why do I still need to learnpageDetailTag?
{{page.Title}}This form is usually only on the page you are currently visitingthat isIt is only valid for a single page, and it depends on the current page context.pageDetailThe strength of the tag lies in the fact that you canon any pageby explicitly specifyingidortokenparameters to obtain them accurately.Any specified single pageDetails data. For example, when you need to display the summary of the "About Us" page on the homepage, at this point{{page.Title}}It is not possible to obtain the title of the "About Us" page, you will need to use it{% pageDetail with name="Title" id="关于我们页面的ID" %}.
2. My single-page content is written in Markdown in the backend, why does the front end display the Markdown source code instead of the rendered HTML?
This is usually because you haven'tpageDetailSpecify the Markdown rendering parameters. If your safe CMS backend has enabled the Markdown editor and the single-page content is written in Markdown, then on the frontend throughpageDetailWhen retrieving content, additional parameters need to be addedrender=trueto allow the system to convert it to HTML before output. For example:{% pageDetail singlePageContent with name="Content" id="123" render=true %}{{ singlePageContent|safe }}{% endpageDetail %}.
**3. If the specified single-page ID does not exist, the page will throw an error