As an experienced website operations expert, I know that it is crucial to flexibly call page data in a high-efficiency content management system like AnQiCMS to build a user-friendly and SEO-friendly website.Today, we will focus on a common and core need: how to accurately obtain the category title, category link, and category description of the current page in the Anqi CMS template.
AnQi CMS Template Secrets: Easily get the category title, link, and description of the current page
In the powerful world of AnQi CMS, content operators 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 delve into the core template tags used in Anqi CMS to achieve this goal, helping you master category data in the simplest and most powerful way.
【en】Overview of AnQi CMS template language
【en】AnQi CMS uses a template language similar to Django, which is intuitive and easy to learn. You will often see two main tags: double braces{{ 变量 }}Used for outputting data, while a single curly brace followed by a percentage sign.{% 标签 %}is used for controlling logic and calling specific function tags. When writing templates, variable names usually follow camelCase naming conventions, such asitem.Title/category.LinkAnd it is case sensitive, be sure to pay attention.
Core tags:categoryDetailThe mystery of
To get the classification information of the current page, the safe CMS provides a feature namedcategoryDetailThe core template tag. The key point of this tag is itsnameParameter, it determines the specific category attribute you want to retrieve.
When you use it on the category list page, category detail page, or any document detail page that belongs to a categorycategoryDetailWhen tagging, if not specifiedidortokenthe parameter, it will intelligently identify and automatically obtainthe current pageThe associated category data.This means you do not need to manually pass the category ID; the system will do it for you, greatly simplifying the template development process.id="分类ID"ortoken="分类别名"to explicitly specify. For users with multi-site operations,siteIdParameters can help you call classification data across sites.
Next, we will detail how to usecategoryDetailtags to obtain the title, link, and description of the classification.
Get Category Title (Title)
Category titles are one of the most common requirements for building navigation or page header information. You can usename="Title"parameters.
If you just want to directly output the title, you can write 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 examplecurrentCategoryTitleSo that it can be referenced multiple times in other parts of the template.
{% categoryDetail currentCategoryTitle with name="Title" %}
<div>当前分类标题:{{ currentCategoryTitle }}</div>
Get the category link (Link)
The category link is a bridge that guides users to browse other related content. Usename="Link"Parameters, you can easily obtain the current category URL.
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” %}