Hello, I am your familiar old friend, a website operator who has been dealing with AnQiCMS for a long time.In daily content management and website optimization work, flexibly using AnQiCMS template tags is the key to improving efficiency and user experience.categoryDetailLook at how it helps us get detailed information about the category in AnQiCMS template.
Understand deeply the AnQiCMS template.categoryDetailTag
In AnQiCMS template development,categoryDetailTags are a core tool that allows us to accurately retrieve detailed data for any category on a website. Whether it is to display the detailed introduction of the category on the category page, or to show the name and link of the category in the article detail page, or to display the thumbnail of a specific category in the sidebar,categoryDetailAll can provide the required data support to help us build dynamic and highly customized website content display.
Basic usage and parameter parsing
categoryDetailThe basic syntax of the tag is{% categoryDetail 变量名称 with name="字段名称" id="1" %}In this structure,变量名称is an optional parameter, if provided, the category detail data obtained will be assigned to this variable for easy reference in subsequent code; if not provided, the label will directly output the value of the specified field.
In order to accurately locate the category to be retrieved,categoryDetailThe tag provides the following key parameters:
id: This parameter allows us to specify the category details to be retrieved by the unique ID of the category.It is not required, the category ID of the current page will be obtained by default on the category page.id="1"The category details with ID 1 will be retrieved.token: Besides ID, we can also use the category URL alias (i.e., the filename part of the custom URL) to specify the category.Likewise, it is optional, and on the category page, it will try to get the URL alias of the current category.token="about-us"The URL alias ofabout-uscategory details will be retrieved.siteId: For users who use the AnQiCMS multi-site management function, if they need to call the category data of a non-current site, they cansiteIdThe ID of the parameter specifies the site. This parameter is usually not required in a single-site environment.
nameThe parameter iscategoryDetailThe core of the tag, which determines which specific field of data we want to obtain from the category details.
Core field details and examples
Let's understand one by onenameSome commonly used fields supported by parameters and their application in templates:
Category ID (Id)
This field returns the numeric ID of the category. It is very useful when you need to associate data through ID or make conditional judgments. Output directly:<div>分类ID:{% categoryDetail with name="Id" %}</div>Assign to variable:{% categoryDetail categoryId with name="Id" %}{{categoryId}}
Category title (Title)
This field returns the category name or title. This is the most common way to display category names on the page.
Direct output:<div>分类标题:{% categoryDetail with name="Title" %}</div>Assign to variable:{% categoryDetail categoryTitle with name="Title" %}{{categoryTitle}}</div>
Category link (Link)
This field returns the access URL of the category. It is used to generate category navigation, breadcrumbs, or any link that needs to jump to the category page.
Direct output:<div>分类链接:<a href="{% categoryDetail with name="Link" %}">查看详情</a></div>Assign to variable:{% categoryDetail categoryLink with name="Link" %}<a href="{{categoryLink}}">查看详情</a></div>
Category description (Description)
This field returns a brief description of the category, usually used for SEO meta description tags or providing an overview on the category list page.
Direct output:<div>分类描述:{% categoryDetail with name="Description" %}</div>Assign to variable:{% categoryDetail categoryDescription with name="Description" %}{{categoryDescription}}</div>
Category content (Content)
This field contains the detailed content of the category, which is usually HTML rich text.On the category detail page, it can be used to display the detailed introduction of the category.It is worth noting that if the Markdown editor is enabled on the backend, the content will be automatically converted from Markdown to HTML.renderparameter,render=trueTranslate,render=falseDo not translate.
Direct output:<div>分类内容:{% categoryDetail with name="Content" render=true %}|safe</div>Assign to variable:{% categoryDetail categoryContent with name="Content" render=true %}{{categoryContent|safe}}</div>
Parent category ID (ParentId)
This field returns the ID of the parent category of the current category. It is very useful when building multi-level category navigation or determining category levels.
Direct output:<div>上级分类ID:{% categoryDetail with name="ParentId" %}</div>Assign to variable:{% categoryDetail parentCategoryId with name="ParentId" %}{{parentCategoryId}}</div>
Category thumbnail large image (Logo)
This field returns the Logo image URL of the category, which is usually a larger size image uploaded on the backend.
Direct output:<div>分类Logo:<img src="{% categoryDetail with name="Logo" %}" alt="{% categoryDetail with name="Title" %}" /></div>Assign to variable:{% categoryDetail categoryLogo with name="Logo" %}<img src="{{categoryLogo}}" alt="{% categoryDetail with name="Title" %}" /></div>
Category thumbnail (Thumb)
This field returns the thumbnail URL of the category, which is usually automatically generated or uploaded in a smaller size, suitable for list pages or small image display.<div>分类缩略图:<img src="{% categoryDetail with name="Thumb" %}" alt="{% categoryDetail with name="Title" %}" /></div>Assign to variable:{% categoryDetail categoryThumb with name="Thumb" %}<img src="{{categoryThumb}}" alt="{% categoryDetail with name="Title" %}" /></div>
Category Banner Group (Images)
This field returns an array containing multiple image URLs, usually used for the carousel Banner or multi-image display on category pages. Since it is an array, it needs to be combined withforLoop tags to iterate output.
Assign to a variable and loop:
{% categoryDetail categoryBannerImages with name="Images" %}
<ul>
{% for imgUrl in categoryBannerImages %}
<li><img src="{{imgUrl}}" alt="{% categoryDetail with name="Title" %}" /></li>
{% endfor %}
</ul>
Number of categorized documents (ArchiveCount)
This field returns the number of documents (articles, products, etc.) contained in the current category. It is suitable for displaying category activity or for filtering and statistical analysis.
Direct output:<div>文档数量:{% categoryDetail with name="ArchiveCount" %}</div>Assign to variable:{% categoryDetail docCount with name="ArchiveCount" %}{{docCount}}</div>
Parameters for the category settings of the document model
For example, if the content model is defined for additional custom fields in the categoryauthororcustom_iconSimilarly, one can also pass throughnameParameters to retrieve the values of these fields.
Get custom fieldscustom_icon:{% categoryDetail with name="custom_icon" %}Loop to display all custom fields (need to assign to a variable):
{% categoryDetail extras with name="Extra" %}
{% for field in extras %}
<div>{{field.Name}}:{{field.Value}}</div>
{% endfor %}
Application scenarios in practice
categoryDetailThe power of tags lies in their flexibility. On the category list page (such as{模型table}/list.html), we can directly use{% categoryDetail with name="Title" %}to get the title of the current category and combine it witharchiveListShow articles under this category. On the article detail page, we can also use it through{{archive.Category.Title}}or use it separately{% categoryDetail with name="Title" id=archive.CategoryId %}Get the detailed information of the article category.This fine-grained control allows us to flexibly display classification information according to the actual page needs, thereby optimizing the user navigation path and improving the organization and readability of the website content.
Summary
categoryDetailTags are an indispensable part of the AnQiCMS template system, providing powerful classification data acquisition capabilities for website operators and template developers. Through precise controlid/tokenandnameParameters, we can freely display the title, link, description, content, images, even custom fields, and provide users with a rich and organized browsing experience. Mastery.categoryDetailThe use of tags will greatly enhance your efficiency and ability to build high-quality websites on the AnQiCMS platform.
Frequently Asked Questions (FAQ)
How can I get the name of the category I am currently browsing on the category list page?For example, in the category list page,article/list.htmlorproduct/list.html)categoryDetailThe tag will default to fetching the category information of the current page, so you just need to use{% categoryDetail with name="Title" %}to directly output the name of the current category.
Ask: Can I display the Logo of the category the article belongs to on the article detail page?Answer: Of course you can. On the article detail page, you usually can{{archive.CategoryId}}Get the ID of the category the current article belongs to. Then, you can use this ID to callcategoryDetailLabel, for example{% categoryDetail with name="Logo" id=archive.CategoryId %}to display the Logo image of the category.
Ask: If my category Banner image is multiple images, how can I display them in the template?Answer: When the category Banner image (Imagesfield) is multiple images, categoryDetailThe tag will return an array of image URLs. You need to assign the array to a variable and then use{% for ... in ... %}Loop through the tag to iterate and display each image one by one. For example:
{% categoryDetail categoryImages with name="Images" %}
{% for imgUrl in categoryImages %}
<img src="{{imgUrl}}" alt="分类图片" />
{% endfor %}