As a senior website operations expert, I am well aware of the critical role of an efficient content management system in the success of a website, especially in terms of flexible content presentation.AnQiCMS (AnQiCMS) provides us with great convenience with its powerful template features and concise Go language architecture.Today, let's delve into how to easily obtain the title, content, and link of a single page in AnQiCMS, so that you can better customize and display website information.
Understanding the 'single page' in AnQiCMS
In AnQi CMS, Single Page usually refers to those pages with relatively independent content, fixed structure, and not frequently updated, such as "About UsThese pages often carry the basic information and brand story of the website, playing an important role in the website structure, yet they are different from continuously updated articles or product details.page/detail.htmlorpage/{单页面ID}.html.
Get detailed information of a single page:pageDetailThe magic use of tags
To get detailed information of a specific single page, Anqi CMS provides a very convenient template tag:pageDetailThis tag acts as an intelligent guide, able to accurately extract the single-page data you need from the database.
1. Accurately locate the target single-page
UsepageDetailWhen labeling, you need to tell it which single page you want. You can do this by selecting the single page.ID(idparameter)or itsURL alias (tokenparameter)Specify accurately. For example, if you know the ID of the "About Us" page is 1, you can write it like this: {% pageDetail with id="1" %}If you are currently on a single page and want to get information about the current page, you do not even need to specifyidortoken,pageDetailtags will intelligently recognize and retrieve data from the current single page.
2. Get the title of a single page
Once the target single page is specified, getting its title is a breeze. You just need to inpageDetailthe label usename="Title"Parameters. This will directly output the clear title of the single page, used for the H1 tag of the web page or the text of the navigation link.
{# 假设获取ID为1的单页面标题 #}
<h1>{% pageDetail with name="Title" id="1" %}</h1>
{# 如果是当前单页面的标题 #}
<title>{% pageDetail with name="Title" %}</title>
3. Extract the rich content of the single page.
The content is the core of a single page. Usename="Content"Parameters, you can easily extract the main content of the page. This part of the content is usually edited by the backend rich text editor, which may contain images, formatted text, etc.
<div class="page-content">
{% pageDetail pageContent with name="Content" %}
{{ pageContent|safe }}
</div>
There are several key points to note:
|safeFilter:If your single-page content contains HTML tags (which is very common in rich text editing), in order for the browser to correctly parse these tags and display the formatted effects instead of displaying the HTML code directly,MustUse together|safeFilter. It tells the template engine that this part of the content is safe and does not need to be escaped.renderParameter (for Markdown):If your security CMS has enabled the Markdown editor to write single-page content, and you want the template to automatically render Markdown syntax into HTML,name="Content"afterrender=true.
4. Get the access link to a single page
In addition to the title and content, the link (URL) to a single page is also indispensable. Usename="Link"The parameter can be used to obtain the access path of this single page, you can apply it to the navigation menu, breadcrumb or jump button within the page.
<a href="{% pageDetail with name="Link" %}">了解更多</a>
5. Other useful information
pageDetailLabels can also help you get the summary of a single page (Description), thumbnails (Thumb) even large images (Logo) and various other information, all of which can be flexibly called in the template by specifying parameters.name.
Get single page list information:pageListFlexible Use of Tags
Sometimes, you may need to display multiple single-page lists in a certain area of the website (such as footer navigation, sidebar), for example, 'About Us', 'Terms of Service', and 'Contact Information', etc.pageListTags come into play.
pageListLabel will return an array of single-page objects, you need to iterate through them byforLoop. In each iteration of the loop, you can access a single single-page object just like you would get a single one.item.Title/item.Link/item.DescriptionAccess the properties of each single page in this way.
<nav class="footer-links">
<ul>
{% pageList pages %}
{% for item in pages %}
{# 判断是否是当前页面,可以添加active样式 #}
<li {% if item.IsCurrent %}class="active"{% endif %}>
<a href="{{ item.Link }}">{{ item.Title }}</a>
{# 如果需要显示简短描述,可以使用item.Description #}
{# <p>{{ item.Description }}</p> #}
</li>
{% endfor %}
{% endpageList %}
</ul>
</nav>
This code will iterate through all the created single-page applications and generate a list item with a title and link for each single-page application. You can adjust it as needed.forContent in the loop, for example, adding thumbnailsitem.Thumbor a brief descriptionitem.Description.
Flexible use of template syntax
The template system of Anqi CMS adopts a concise syntax similar to Django, making the invocation of content intuitive and efficient.
- Variable reference:Use double curly braces
{{变量名}}to output the value of the variable, for example{{ item.Title }}. - Label usage:Use
{% 标签名 参数 %}To call functional labels, for example{% pageDetail %}and{% pageList %}. - Filter:Through the pipe character
|To apply filters, to process variables, for example|safeTo prevent HTML escaping.
By masteringpageDetailandpageListThese powerful template tags allow you to easily retrieve and display the title, content, and link of a single page in the Anqi CMS, thereby providing users with richer and more friendly content experiences.
Common Questions (FAQ)
Why does the single-page content display HTML code instead of the parsed effect?This is usually because you did not use
|safeFilter.The AutoCMS for security reasons, defaults to escaping all output content to HTML.{{ pageContent|safe }}.Can I use
pageDetailTag does not specify ID or URL alias, directly get the single page information of the current page?Yes, it can be done completely. When your template file is used to render a single page (such aspage/detail.html或`page/{English}