As an experienced website operations expert, I am well aware that the core value of a content management system (CMS) lies in the seamless connection between its backend configuration and frontend display.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture based on the Go language and flexible design.Today, let's delve into the development of Anqi CMS templates in depthcategoryListLabel, how does it closely correspond to the background "Document Classification" function, and how can we skillfully use this association to build powerful website features.

The background 'Document Classification' feature: builds the skeleton and order of content

In the AnQi CMS backend management interface, the 'Document Category' feature is the cornerstone of organizing website content.It is not just a simple classification of articles, products, and other content, but also builds a clear and logical hierarchical structure for these contents.Imagine your website as a library, document classification is like the bookshelves and sections in a library, each book (document) must be placed on some shelf.

When you create or edit a document category in the background, AnQi CMS provides an extremely rich set of configurable options, which together define the characteristics and behavior of a category:

  • Document Model (Content Model)This is the soul of the category. Each category must be bound to a content model, such as 'Article Model' or 'Product Model', and once bound, it cannot be changed.This choice determines the data structure and fields that all documents in this category will follow (such as articles having authors, products having prices, etc.).
  • Parent Category (Parent Category)By setting the parent category, you can easily build a multi-level classification structure, such as "News Center" under "Company News" and "Industry Dynamics".This is crucial for the navigation and content aggregation of the website.
  • Category Name, DescriptionThis is the basic information displayed to users and search engines for the category, directly affecting users' understanding of the category content and SEO effect.
  • Custom URL (Custom URL) and SEO related settingsAllow you to set a friendly URL for categories, and configure independent SEO titles and keywords to further optimize search engine inclusion.
  • Category Template, Document TemplateThese settings determine which template file the system will call to render the page when the user visits the category page or the document detail page under the category.This high degree of customization allows you to design completely different visual styles and layouts for different types of categories.
  • Banner Image, ThumbnailThis provides visual elements for the category page, enhancing aesthetics and attractiveness.
  • Category ContentAllow you to directly add rich text content to categories, which is very useful when creating pages like 'About Us' or categories with introductory text.

In short, the "document classification" feature of the backend is a comprehensive content organization and metadata definition center, which lays a solid foundation for the content structure, display logic, and search engine optimization of the website.

in the templatecategoryListLabel: Dynamic display of classification data

When you are doing the template development of AnQi CMS,categoryListThe tag is the key bridge connecting the background "document category" with the front-end page display.It is a powerful data acquisition tool that allows developers to dynamically extract classified data from the backend and present it on the website.

categoryListThe core function of the tag is to loop through and display the category information you set in the background. It is usually wrapped in a{% categoryList categories with ... %}and{% endcategoryList %}structure, wherecategoriesIs the variable name you customized, used to represent the category list obtained in the loop.

This tag uses a series of parameters to accurately filter and control which categories to obtain.

  • moduleIdThis parameter directly corresponds to the "Document Model" selected for the category in the background. By specifyingmoduleId="1"(Assuming 1 is the article model ID), you can only retrieve all categories belonging to the article model.This relationship ensures that the category data obtained by the front-end remains consistent with the data structure of the back-end.
  • parentIdIt is closely related to the background "parent category" setting. You can setparentId="0"Get all top-level categories, or specify a specific category ID to get all subcategories under it. This parameterized capability makes it easy to build multi-level navigation menus.
  • limit: Controls the number of categories returned, helping to optimize page loading and display layout.
  • all: When set toall=true, all categories will be retrieved, ignoring the hierarchy.

IncategoryListInside the loop of tags, each category item (in our example isitemAll expose rich properties, which directly map to the various information you fill in in the background "Document Classification":

  • item.Id/item.Title/item.Description: Corresponding to the ID, name, and introduction of the background category.
  • item.LinkThis is the category page link, which is automatically generated according to the "Custom URL" set in the "Document Category" backend and the pseudo-static rules of the website, ensuring the correctness of the front-end link.
  • item.Logo/item.Thumb: Corresponds to the thumbnail and full image uploaded for categories in the background (Banner images are usually through custom fields orcategoryDetailobtaining).
  • item.HasChildrenA very useful boolean value used to determine whether the current category has subcategories, which can control whether the dropdown arrow or submenu is displayed when building a dynamic navigation menu.
  • item.ArchiveCount: Show how many documents are in this category, convenient for content statistics and display.

Reveal deep connections: How backend configuration drives frontend display.

categoryListThe corresponding relationship between tags and the background "Document Classification" function is the core embodiment of the flexibility of AnQi CMS. Together, they constitute a powerful content management and publishing system:

  1. Data source and consumer: The background "Document classification" is the producer and manager of original data, defining all attributes of classification; andcategoryListThe label is the consumer of these data, it intelligently extracts and formats these data according to the developer's requirements from the background database.

  2. Structured and dynamicThe background "Document Classification" function forces you to manage the content structurally, bind content models, and establish hierarchical relationships. AndcategoryListTags make use of this structured information to dynamically construct various modules such as navigation, category lists, content aggregation, etc. on the front-end, without hard coding, which greatly improves development efficiency and maintainability.When you adjust the category name, level, or associated model in the background, the front-end page will synchronize the update immediately after clearing the cache, without modifying any template code.

  3. Precise parameter control:categoryListofmoduleIdParameters, allowing you to easily filter categories under specific content models, for example, displaying a list of "news articles" categories on one page, and a list of "product catalogs" on another page.parentIdParameters can accurately control the level of the categories obtained, whether it is top-level navigation or sidebar subcategories, all can be realized through simple parameter configuration.

  4. Content and presentation separation: The backend is responsible for defining 'what is' and 'what has', while the front-end template is responsible for 'how to display'. For example, you set the 'category template' for a certain category in the backend tospecial_list.htmlWhen the user visits this category page, AnQi CMS will load this specific template and thencategoryListThe label's role is to list the name and link information of this category when it is listed on other pages (such as the homepage, sidebar), and still be able to get its name, link and other information.

  5. Building complex navigation and content index: Thanks tocategoryListfor the good support of the hierarchical relationship (parentIdanditem.HasChildren) we can easily build a responsive multi-level dropdown menu in the template. By nestingcategoryListTags can realize unlimited hierarchical classification navigation, providing users with a clear website structure.

Practical application: Give full play tocategoryListthe power.

MasteredcategoryListThe correspondence with the background "Document Category" allows you to implement various flexible content displays in Anqi CMS:

  • Main Navigation MenuUtilizemoduleIdandparentId="0"Combine to get the top-level category,item.HasChildrenCheck if there is a subcategory and then use it nestedcategoryListto build a multi-level dropdown menu.
  • Sidebar category list: Use according to the current page's category ID,parentId="当前分类ID"To get同级 or 子级分类,forming context-related navigation.
  • Modular display on the homepageIn the homepage template, bymoduleIdGet popular categories under different content models and combinearchiveListTags, displaying the latest or recommended documents under each category.
  • Content index pageBuild a page listing all categories or indexing them alphabetically to help users quickly locate the content they are interested in.

Frequently Asked Questions (FAQ)

**1. Why