How to get the details of the current access category, including the title, link, description, and custom fields?

As an experienced CMS website operator, I am well aware of the importance of high-quality, easily accessible content information for website user experience and search engine optimization.In AnQi CMS, obtaining detailed information about the current visited category is a very basic and frequent requirement in website construction. Whether it is used for page titles, navigation breadcrumbs, or detailed introductions on category pages, it is necessary to accurately call these data.

Our Anqi CMS provides a powerful and flexible template tag system, making it extremely convenient to obtain the title, link, description, and even custom fields of the current visited category.

Get the basic information of the current visited category

In the Anqi CMS template, obtaining the detailed information of the current category mainly depends oncategoryDetailThe tag is powerful because it can automatically identify the category of the current page and extract the required data when you do not need to specify the category ID or alias.This greatly simplifies the complexity of calling category information on the category page or in the document detail page.

For example, on the category list page (such as{模型table}/list.htmlor{模型table}/list-{分类ID}.html) or the document detail page (such as{模型table}/detail.htmlor{模型table}/detail-{文档ID}.html)categoryDetailTags can intelligently obtain the current context classification data.

Title (Title)

To display the title of the current visited classification, we can usecategoryDetaillabel and specifynameparameters for"Title". This title is usually used for the main title of a category page, or as the text of a category link in a document detail page.

<div>当前分类标题:{% categoryDetail with name="Title" %}</div>

Link (Link)

The current category's URL link is crucial for building navigation, breadcrumbs, and optimizing internal link structure. By usingnamethe parameter to"Link",categoryDetailthe tag will return the complete link of the category.

<a href="{% categoryDetail with name="Link" %}">前往此分类页面</a>

Description and Content

Category descriptions are usually a brief text summary, commonly used for page meta descriptions (meta description) or as brief introductions in category lists. AndContentFields can carry more rich rich text content, used for the detailed introduction of the category page.

To get the category description:

<div>分类描述:{% categoryDetail with name="Description" %}</div>

To get the detailed content of the category:

<div>分类详细内容:{% categoryDetail categoryContent with name="Content" %}{{categoryContent|safe}}</div>

Please note that whenContentWhen a field contains HTML or other rich text format, in order to ensure that the content is rendered correctly and not automatically escaped, we usually need to use|safeFilter. If the category content is written using Markdown, Anqi CMS will default to converting it to HTML, and you can alsorender=trueorrender=falseParameters to manually control whether Markdown rendering is performed.

Get Custom Field

The strength of AnQi CMS lies in its flexible content model, allowing operators to add various custom fields to categories.These custom fields greatly expand the expressiveness of classification information, for example, special icons, color codes, additional introduction text, or unique image sets can be added.

To obtain the specific custom field of a category, if you know the name of the field (defined as the 'call field' in the back-end content model), you can access it directly throughnameThe parameter is called. For example, if you define a category namedcustomIcon: custom field

<div>自定义图标:<img src="{% categoryDetail with name="customIcon" %}" alt="分类图标" /></div>

In addition to directly calling specific fields, Anqi CMS also provides a method to display all custom fields through iteration.This is very useful for the scenario where it is needed to dynamically display all the additional properties of a category.Through obtainingname="Extra"We can get an array containing all the custom fields, then useforthem in a loop.

{% categoryDetail extras with name="Extra" %}
{% for field in extras %}
  <div>{{field.Name}}:{{field.Value}}</div>
{% endfor %}

field.NameThe field name (or the parameter name you set in the background) will be displayed, whilefield.Valuethe corresponding value will be displayed.

In addition, the category supports some built-in "custom" image fields, such asLogoUsed for the main image,ThumbUsed for thumbnails, as well asImagesUsed for multiple banner images. The calling method of these fields is similar to that of common custom fields.

<div>分类主图:<img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}" /></div>

IfImagesThe field contains multiple images and usually requires cooperationforLoop to display:

{% categoryDetail bannerImages with name="Images" %}
{% if bannerImages %}
<div class="category-banners">
  {% for img in bannerImages %}
  <img src="{{img}}" alt="{% categoryDetail with name="Title" %} banner" />
  {% endfor %}
</div>
{% endif %}

By using the above method, the operation personnel of Anqi CMS can easily and flexibly obtain and display all the detailed information of the current access category, thereby creating a rich-content, clear-structured, and well-user-experienced website page.The mastery of these abilities is crucial for improving the effectiveness of content marketing and the overall competitiveness of the website.

Frequently Asked Questions

Q1: How do I get the details of a specific category not currently being accessed?

A: If you need to get the details of a specific category not currently being accessed on the page, you cancategoryDetailthe tag throughidortokenParameters to specify the target category.idParameters accept the numeric ID of the category, whereastokenParameters accept the URL alias of the category. For example, to get the title of the category with ID 10:{% categoryDetail with name="Title" id="10" %}; or by aliasabout-usGet category link:{% categoryDetail with name="Link" token="about-us" %}.

Q2: Does the category content support Markdown format? How to control rendering?

A: Yes, if the Markdown editor is enabled in the content settings of your Anqi CMS backend, and the category content is written in Markdown,categoryDetaillabel'sContentThe field will automatically convert Markdown to HTML. If you need to manually control the rendering process, you can addContentthe field withrenderparameter. Set it torender=trueYou can force Markdown conversion, andrender=falseit will prevent conversion and directly output the original Markdown text. Please make sure to cooperate|safeThe filter to ensure the correct display of HTML content.

Q3: If I need to display a list of categories instead of the details of a single category, which tag should I use?

A: For displaying the category list, you should usecategoryLista tag. This tag allows you to filter by multiple conditions (such asmoduleIdto get the categories under a specified content model,parentIdto get child categories or top-level categories,limitControl the quantity and others) to get multiple categories. It will return an array of category objects, and you need to go throughforLoop through this array, then from each category item (itemRetrieve the title, link, and description information from it. For example, retrieve the top-level category list of the article model: {% categoryList categories with moduleId="1" parentId="0" %}{% for item in categories %}<a href="{{item.Link}}">{{item.Title}}</a>{% endfor %}{% endcategoryList %}.