As an experienced website operation expert, I am fully aware that in an efficient content management system like AnQiCMS, it is crucial to flexibly call page data to build a user-friendly and SEO-friendly website.Today, we will focus on a common and core requirement: how to accurately obtain the category title, category link, and category description of the current page in the Anqi CMS template.
The Anqi CMS template secret: easily get the current page category title, link, and description
In the powerful world of Anqi CMS, content managers and developers can always find efficient tools to manage and display information.How to accurately obtain the information of the current page's category (Category), such as its title, link, and detailed description, is an indispensable part of building a dynamic website.This article will deeply explore the core template tags used in Anqi CMS to achieve this goal, helping you master the classification data in the most concise and powerful way.
Anqi CMS template language overview
AnQi CMS uses a template language similar to Django, which has an intuitive syntax and is easy to learn. You will often see two main tags: double curly braces{{ 变量 }}Used for outputting data, while a single curly bracket followed by a percentage sign{% 标签 %}is used for controlling logic and calling specific function tags. When writing templates, variable names usually follow camel case naming, such asitem.Title/category.LinkAnd be case sensitive, pay attention.
Core tags:categoryDetailThe mystery of
To get the category information of the current page, AnQi CMS provides a namedcategoryDetailcore template tag. The key to this tag is itsnameThe parameter, it determines the specific category attributes you want to retrieve.
When you are on the category list page, category detail page, or any document detail page that belongs to a categorycategoryDetailif a tag is not specifiedidortokenThe parameter, it will intelligently recognize and automatically obtainCurrent pageThe associated category data. This means you do not need to manually pass the category ID, the system will complete the identification for you, greatly simplifying the template development process.Of course, if you need to obtain specific category information from a non-current page, you can also do so byid="分类ID"ortoken="分类别名"To specify clearly. For users with multi-site operations,siteIdParameters can help you call classification data across sites.
Next, we will explain in detail how to usecategoryDetailTags to get the category title, link, and description.
Get the category title (Title)
The category title is one of the most common requirements for building navigation or page header information. You can usename="Title"Parameter to achieve.
If you just want to output the title directly, you can do it like this:
<div>当前分类标题:{% categoryDetail with name="Title" %}</div>
To make the template code clearer and easier to manage, you can also assign the obtained title to a variable, for examplecurrentCategoryTitleReference it multiple times in other places of the template.
{% categoryDetail currentCategoryTitle with name="Title" %}
<div>当前分类标题:{{ currentCategoryTitle }}</div>
Get the category link (Link)
The category link is a bridge guiding users to browse other related content. Usename="Link"Parameters, you can easily obtain the URL of the current category.
Directly output the link:
<div>当前分类链接:<a href="{% categoryDetail with name="Link" %}">点击进入</a></div>
Assign the link to a variable: “`twig {% categoryDetail currentCategoryLink with name=“Link” %}