English CMS (EnglishCMS) as an efficient and flexible enterprise-level content management system, provides many conveniences in content publishing and SEO optimization. Among them, URL alias (tokenThe flexible use of parameters is crucial for improving the user experience and search engine optimization of a website. Today, let's delve into how to use the template in AnQiCMS, especially usingpageDetailLabel it, make full use oftokenthe power of parameters.
UnderstandingtokenThe core value of (URL alias)
In AnQiCMS,tokenActually, it is the 'Custom URL' or 'URL Alias' we set for articles, categories, or single pages in the background.This alias is not just for beautifying the URL, it also carries important SEO and content management significance.An concise and meaningful URL alias can help search engines better understand the content of the page, and it can also enhance the user's memory and trust in the URL.
AnQiCMS in creating content, by default, will automatically generate a pinyin form URL alias based on the page title.Of course, as an operator, we can completely edit and customize this alias manually according to our own SEO strategy or brand needs.It should be noted that this custom URL alias must be unique throughout the entire website, and the system will also perform strict verification in the background.
pageDetailLabel: a powerful tool for obtaining single-page information
In the template development of AnQiCMS,pageDetailTags are core tools used to obtain detailed information about a single page. Whether it's a company introduction page like “About Us” or “Contact Us”, or a custom activity landing page,pageDetailCan help us easily retrieve its title, content, description, and other data.
Under normal circumstances, when we are on a single-page page by ourselves,pageDetailTags do not require additional parameters to intelligently retrieve all information on the current page. For example, use directly{% pageDetail with name="Title" %}It can display the title of the current page. When we want to call a specific single-page content on other pages (such as a certain block on the homepage), we need to specify it explicitly.pageDetailLabel to get which page's data. At this time, we usually use the single page ID (id) to specify.
tokenParameter inpageDetailapplication of the label
However, in some scenarios, relying solely on ID to call single-page data may not be intuitive, or we may prefer to refer to it through the semantic identification of the page. At this time,tokenThe parameter becomes particularly important.
tokenThe parameter allows us to accurately locate and obtain the detailed information of the page through the single-page URL alias. Its usage is very concise and clear, just inpageDetailtag.token="你的URL别名".
For example, we assume that a URL alias has been created in the backgroundabout-usThe "About Us" single page, and we want to display its brief introduction at the bottom of the website or in some module on the homepage, instead of linking directly to it. We can use it in the template like this:
{# 假设有一个URL别名为 "about-us" 的单页面 #}
{% pageDetail aboutUsPage with token="about-us" %}
<div class="footer-about">
<h3>{{ aboutUsPage.Title }}</h3>
<p>{{ aboutUsPage.Description }}</p>
<a href="{{ aboutUsPage.Link }}">了解更多我们</a>
</div>
{% endpageDetail %}
In this code,aboutUsPageThis variable will carry the URL aliasabout-usof the single page. We can conveniently extract the title, description, link, and other information for display.
Give another example, if our website has a privacy policy page namedprivacy-policy, and it needs to reference the full content of the page in the user registration agreement (not just a link), usetokenParameters can be called very conveniently and clearly:
{# 假设有一个URL别名为 "privacy-policy" 的单页面,用于展示隐私政策 #}
<div class="registration-agreement">
<h2>用户注册协议</h2>
<p>请您仔细阅读本协议,并勾选同意...</p>
<h3>隐私政策声明</h3>
{% pageDetail privacyPolicy with token="privacy-policy" %}
{# 在这里调用隐私政策页面的内容,并使用 |safe 过滤器确保HTML内容正确渲染 #}
<div class="privacy-content">
{{ privacyPolicy.Content|safe }}
</div>
{% endpageDetail %}
<p>...通过注册即表示您同意以上所有条款。</p>
</div>
In this way, even if the ID of the privacy policy page changes in the future, as long as its URL aliasprivacy-policyThe content remains unchanged, so there is no need to modify the reference code in the template, which greatly enhances the robustness and maintainability of the template.
Application scenarios and advantages
totokenParameters integratedpageDetailThe use of tags can bring many benefits to website operation:
- Improved code readability and maintainability:Proceed directly
tokenCiting the page is more intuitive than using numeric IDs, making the template code's intent clear even to non-developers, and making it easy to see which page's content is being called, thus reducing the maintenance cost. - Enhance template flexibility:Whether in the global public area (such as footer, sidebar) or specific content modules, we can flexibly call any specified single page's content without worrying about the change of page ID.
- SEO-friendly development:
tokenIt is a SEO-friendly URL alias itself, and it is used to refer to content in the template, which also indirectly strengthens the association between content and semantic URL.
As experienced website operators, we fully understand that content updates and flexible template adjustments are the norm in our daily work. Proficient inpageDetaillabel combined withtokenThe use of parameters can undoubtedly make our content operation more convenient and efficient, ensuring the stability and efficiency of the website's front-end display.
Common Questions (FAQ)
Question: When should I prioritize the use of
tokenInsteadidCall single page?Answer: When you want the code to be more semantically meaningful and readable, and you are confident that the single page's URL alias (token) will be more stable than its database ID, it is preferable to use it.tokenFor example, when calling some fixed functional pages (such as "About UstokenIt makes template code clearer and reduces the risk of failure due to changes in background IDs. However, attention should be paid to it.tokenThe uniqueness across the entire site ensures that there will be no confusion.Q: If I set
tokenThe single page corresponding to the parameter does not exist, will the template report an error?Answer: Usually, iftokenThe single page specified by the parameter does not exist,pageDetailThe label will not directly cause the template rendering to fail. It will only return an empty data object. This means that in{% pageDetail yourPageData with token="non-existent-token" %}…{% endpageDetail %}the block,yourPageDataThe variable will not contain any valid page information, so the internal references{{yourPageData.Title}}will be displayed as blank. To avoid this situation, you can add{% if yourPageData %}This condition judgment ensures that rendering is only performed when page data exists.Q:
tokenIs the 'URL alias' referred to by the parameter the same concept as the 'custom URL' I set in the AnQiCMS backend?Answer: Yes, it is the same concept.tokenParameters in AnQiCMS template tags are used to refer to the 'custom URL' you set for single pages (as well as articles, categories, and other content) in the background