I want to display a specific icon or style in the template based on the content model's ID, what information can the `moduleDetail` tag provide to assist in the implementation?

Calendar 👁️ 82

Security CMS template customization secret: skillful usemoduleDetailTags, making different content models shine with unique charm

In today's content-driven digital world, the attractiveness of a website does not only come from the quality of its content, but also from the exquisite form of its presentation and the smooth user experience.AnQi CMS knows this, it endows the operator with high flexibility with its powerful content model function, enabling them to create diverse content structures such as articles, products, events, etc. according to different business needs.However, having a flexible content model is not enough. How to let these different types of content have their own unique 'identity identifier' and visual presentation in the front-end template is a key link to improve the professionalism and user experience of the website.

Imagine when a user browses your website, an in-depth analysis article and a carefully crafted product introduction, if they can be visually distinguished by a dedicated icon or a unique style, it will undoubtedly greatly improve the recognition of information, guiding users to understand the content attributes more quickly. Today, let's delve into a powerful template tag in Anqi CMS -moduleDetailHow it helps us easily implement these personalized icons and style displays in the template based on the content model ID.

The unique charm of the Anqi CMS content model.

One of the core strengths of AnQi CMS is its flexible content model.This means you can fully define content types according to your own business logic, for example, creating an 'article model' for news information, a 'product model' for e-commerce goods, or an 'event model' for online activities.Each model can have its own unique fields, thus achieving highly customized content management.This design philosophy makes Anqi CMS not only a content publishing tool but also a content operation platform that can adapt to various business scenarios.

But when these diverse contents gather at the front end of the website, how can we identify the content models behind them? This leads tomoduleDetailthe application of tags.

moduleDetailLabel: The Window to Insight the Essence of Content Model

moduleDetailThe label, as the name implies, is used to obtain the 'document model detail data'.It's like a detective that can reveal the details of the content model it belongs to based on the clues of the content.By this tag, we can obtain the ID, name, link, and other key data of the content model, thereby providing the basis for dynamic display in the template.

This label's usage is very intuitive. If you are on a document detail page or in a document list loop, and you are already able to access the current document'sModuleId(The ID of the document model you belong to), then you can call it like this:

{% moduleDetail currentModuleInfo with id=archive.ModuleId %}

Here, archive.ModuleIdIs a hypothetical variable representing the content model ID obtained from the current document object.currentModuleInfoThis is a custom variable name we define for the model detail data obtained, for easy reference.

moduleDetailThe label can provide the following valuable information:

  • Id: The unique identifier of the content model. This is the direct basis for us to display specific icons or styles based on the model ID.
  • Title: The display title of the content model, such as "Article Model", "Product Model". This is usually the friendly name set by the administrator in the background for the model.
  • Name: The system name of the content model, usually a string in English, which may be used for URL aliases, etc.
  • Link: The home page link of the content model.
  • TableName: The table name corresponding to the content model in the database.

In this information,IdandTitle(orName) is the most commonly used attribute for implementing dynamic style and icon display.

Practice Exercise: Apply Custom Styles or Icons Based on Content Model ID

Now, let's look at how to make use of several actual scenarios,moduleDetailTags and the information they provide inject vitality into your security CMS website template.

Scenario one: Display exclusive icons based on model ID.

Assuming your website has an article model (ID 1) and a product model (ID 2), you want to display an icon representing its type next to each article or product title.

You can write the code like this at an appropriate location in the template, such as next to the document title:

{% set docModuleId = archive.ModuleId %} {# 假设从当前文档(archive)对象获取模型ID #}
{% moduleDetail moduleData with id=docModuleId %}

<h3 class="post-title">
    {% if moduleData.Id == 1 %}
        <i class="fas fa-newspaper article-icon" title="文章"></i> {# 文章图标 #}
    {% elif moduleData.Id == 2 %}
        <i class="fas fa-box-open product-icon" title="产品"></i> {# 产品图标 #}
    {% else %}
        <i class="fas fa-file-alt default-icon" title="其他内容"></i> {# 默认图标 #}
    {% endif %}
    <a href="{{ archive.Link }}">{{ archive.Title }}</a>
</h3>

This code first retrieves the ID of the content model the current document belongs to, then throughmoduleDetailTag to obtain the complete information of the model and store it inmoduleDatathe variable. Then, using simpleif-elif-elselogic, according tomoduleData.Idvalue, dynamically insert different CSS icon classes (such asfas fa-newspaperThus, it distinguishes articles and products visually.

Scenario two: Apply dynamic styles based on the model name.

In addition to displaying icons, we can also add dynamic CSS classes to the entire content block or specific elements based on the name of the content model, in order to provide richer style control.This is particularly useful when it comes to distinguishing the overall layout of article cards, product list items, and so on.

{% set docModuleId = archive.ModuleId %}
{% moduleDetail moduleData with id=docModuleId %}

{% set moduleClass = '' %}
{% if moduleData.Name == "文章模型" %}
    {% set moduleClass = 'content-card-article' %}
{% elif moduleData.Name == "产品模型" %}
    {% set moduleClass = 'content-card-product' %}
{% else %}
    {% set moduleClass = 'content-card-default' %}
{% endif %}

<div class="content-card {{ moduleClass }}">
    <div class="content-thumbnail">
        <img src="{{ archive.Thumb }}" alt="{{ archive.Title }}">
    </div>
    <div class="content-body">
        <h4 class="content-title"><a href="{{ archive.Link }}">{{ archive.Title }}</a></h4>
        <p class="content-description">{{ archive.Description }}</p>
    </div>
</div>

In this example, we base it on.moduleData.NameDynamic setting of a content model name.moduleClassVariable, then apply it todivthe class attribute of the container. This way, we can target it in CSS..content-card-articleand.content-card-productWrite different style rules to achieve visual differentiation in layout, background, borders, etc.

Scenario three: Obtain model links to build navigation or filtering

moduleDetailNot limited to style, it can also provide the model page ofLink. This is very useful for building dynamic navigation menus or filters.

{% moduleDetail articleModule with name="Link" id=1 %}
{% moduleDetail productModule with name="Link" id=2 %}

<nav class="main-navigation">
    <ul>
        <li><a href="{{ articleModule }}">查看所有文章</a></li>
        <li><a href="{{ productModule }}">浏览产品目录</a></li>
    </ul>
</nav>

Here we directly obtain the root links of the article model and product model, which can be easily integrated into the website navigation, allowing users to one-click access to the list page of a specific content model.

A more flexible implementation: combining CSS variables and mappings

When you have a variety of content models, within the template,if/elifConditional judgments may become lengthy. To maintain code conciseness and maintainability, you can consider combining CSS variables or performing more advanced mapping in the background.

An elegant way is to, in the template, for the content container

Related articles

The `moduleDetail` tag retrieves the model link (`Link`) - is it an absolute path or a relative path, and does it support customization?

## AanQi CMS `moduleDetail` tag: Is the model link path absolute or relative?The comprehensive analysis of the custom mystery As an experienced website operations expert, I am well aware that the subtle details of content presentation in every CMS system may have a profound impact on the website's SEO performance and user experience.AnQiCMS (AnQiCMS) leverages its efficient Go language genetics and enterprise-level positioning, also showing its unique strengths in URL structure management.Today, let's delve deeply into a problem that often arises in template development and content operations

2025-11-07

How to use the `moduleDetail` tag to dynamically display different content models' SEO keywords (`Keywords`) and descriptions (`Description`) in the template?

In the powerful ecosystem of AnQi CMS, the flexible content model is one of its core advantages, granting us the ability to build diverse content forms according to business needs.As an expert who has been deeply involved in website operations for many years, I know that no matter how rich and colorful the content is, its value will be greatly discounted if it cannot be efficiently identified and accurately presented to the target users by search engines.That is the foundation of all this, which is excellent SEO optimization. Anqi CMS provides many advanced tools in the field of SEO, from static rules to Sitemap generation, to keyword library management

2025-11-07

Does the AnQi CMS built-in 'article model' and 'product model' allow deletion? If not, why?

## The Core Pillars of AnQi CMS: The Mystery of 'Un deletable' Articles and Product Models As an experienced website operations expert, I fully understand the importance of an efficient and stable content management system (CMS) for a corporate website.Among many excellent CMS systems, AnQiCMS (AnQiCMS) has won a good reputation among small and medium-sized enterprises, self-media operators, and multi-site management users with its high-performance architecture based on the Go language, flexible content model, and SEO-friendly features.

2025-11-07

Will deleting a content model also delete all documents and categories under it? What are the data protection measures?

AnQi CMS is an efficient and flexible enterprise-level content management system, and its 'Content Model' feature is undoubtedly one of its core highlights.It allows us to customize the content structure according to business needs, whether it's articles, products, or events, it can easily handle them.However, while using this powerful function, we will also face an important issue: how will the system handle the data under the content model when it needs to be deleted?Will it only delete the model itself, or will it 'pull the strings' and delete all associated documents and categories as well?

2025-11-07

The `moduleDetail` tag is available on non-model related pages (such as the homepage)? How to safely obtain and use model information?

AnQiCMS (AnQiCMS) provides great convenience for website operators with its flexible content model and powerful template tag system.However, in practice, we often encounter a question: whether a tag like `moduleDetail`, which is usually used to obtain information about a specific content model, is still available on pages such as the homepage of a website that is not related to the model.How can it be used safely and effectively to obtain the required model information?As an experienced website operations expert, I will take you deep into this topic.

2025-11-07

How to combine the `archiveList` tag to filter and display the document list of a specific content model based on `moduleId`?

## AnQiCMS Content Model Deep Guide: How to Use `archiveList` to Precisely Filter Document Lists As a veteran in website operation for many years, I deeply understand the importance of a flexible and efficient content management system for a corporate website.AnQiCMS with its efficient architecture based on the Go language and highly customizable features, provides us with strong support in the content management field.

2025-11-07

When a content model has custom fields (such as `author`), how can these model-specific custom fields be called in the `archiveDetail` tag?

Unlock the charm of AnQi CMS content model custom fields: advanced application of `archiveDetail` tag As a senior website operations expert, I fully understand the importance of a flexible content management system in improving operational efficiency and achieving personalized content display.AnQiCMS (AnQiCMS) excels in this aspect with its efficient architecture based on the Go language and excellent customizability.

2025-11-07

What is the collaboration or difference between the `archiveParams` tag and the `moduleDetail` tag in obtaining custom field information of the content model?

Today, with the increasing diversity of digital content, a flexible content management system (CMS) is undoubtedly the key to improving efficiency and achieving personalized display for enterprises and self-media operators.AnQiCMS (AnQiCMS) with its powerful content model function enables users to deeply customize the content structure according to their own business needs.However, when we delve into the template level, trying to retrieve this customized data, we may encounter some questions: `archiveParams` tag and `moduleDetail` tag

2025-11-07