How to display different fields in `moduleDetail` based on model type (such as `article model` or `product model`)?

Calendar 👁️ 58

Deep analysis of AnQiCMS: How tomoduleDetailDisplay different fields according to the model type to create a personalized content experience

As an experienced website operations expert, I know that a truly excellent content management system is not only able to publish content, but also needs to be able to flexibly adapt to various content forms.AnQiCMS (AnQiCMS) performs exceptionally well in this regard, its powerful "content model" function is the secret weapon for us to achieve personalized content display.moduleDetailUnder the help of tags, according to different content models (such as article models, product models, etc.), dynamically display matching fields on the front-end page, thereby bringing readers a more accurate and richer browsing experience.

Understand the content model mechanism of Anqi CMS: the 'blueprint' of content

In AnQi CMS, the content model is like the 'blueprint' or 'skeleton' of various contents.It defines which information fields a certain type of content should include.For example, an 'article model' usually has fields such as title, content, author, and publication date; while a 'product model' may require product name, price, inventory, specifications, and multiple image displays.

The strength of AnQi CMS lies in the fact that it not only provides built-in models such as 'Article Model' and 'Product Model', but also allows us to customize more content models according to business needsCustomize more content modelsand add for each modelexclusive custom fieldsThese custom fields are the key to our implementation of content differentiation display.

You can access the Anqi CMS backend内容管理 -> 内容模型In Chinese, find and manage these models and their custom fields.After configuring unique fields for different content models, we can intelligently retrieve and display these fields in the frontend template based on the current content model type.

Second,moduleDetailLabel: Identify the 'identity' of the content

In the template, to display different fields according to the model type, the first thing to do isIdentify which model the content on the current page belongs to. At this point,moduleDetailThe tag comes in handy.

moduleDetailThe tag is used to obtain the details of the model belonging to the current content. Through it, we can easily obtain the ID of the current model (Id) or the model table name (TableName),These are the basis of our conditional judgment.

Generally, in the content detail page (for example{模型table}/detail.html),we can use it like thismoduleDetailto get the information of the current model:

{# 获取当前模型的详细信息,并赋值给变量 currentModule #}
{% moduleDetail currentModule %}

Now,currentModuleVariables include the current content model data, for examplecurrentModule.IdIt will return the model's numeric ID, whereascurrentModule.TableNameIt will return the English table name of the model (such asarticle/productetc.). In actual development, useTableNameJudging is usually more readable.

Third,archiveDetailCombined with custom fields in a clever way: refined display

Once we pass throughmoduleDetailIdentified the type of the content model, the next task is to use this type toarchiveDetailorarchiveParamslabels to display the corresponding fields.

1. Accurate judgment, pinpoint display of specific fields

This is the most commonly used and most intuitive method. We go throughifConditional judgmentcurrentModule.TableNamevalue, and then use the corresponding code block, usingarchiveDetailtag to call the special fields of the model

Assuming we have two models:

  • Article model (TableName:)article)In addition to the default title and content, there is also a custom field "author".
  • Product Model (TableName:product)In addition to the default title and content, there are custom fields "product price (price)" and "product specifications (specs)."}]

Before yourdetail.htmlIn the template, you can write logic like this:

`twig {# Firstly, get the complete data of the current content, which is convenient to call general fields, such as title, content #} {% archiveDetail archive %}

{# Get current model information #} {% moduleDetail currentModule %}

<h1 class="title">{{ archive.Title }}</h1>
<div class="meta-info">
    <span>发布日期:{{ stampToDate(archive.CreatedTime, "2006-01-02") }}</span>
    <span>浏览量:{{ archive.Views }}</span>
    {# 您可以在此处添加其他通用字段,如分类、标签等 #}
</div>

{# 根据模型类型显示不同的字段 #}
{% if currentModule.TableName == "article" %}
    <div class="article-meta">

Related articles

How to judge whether the `userDetail` user group is VIP and display exclusive identification in AnQiCMS templates?

In the daily operation of AnQiCMS, we often encounter the need to provide differentiated services and display content for different user groups.For VIP members, displaying a dedicated identifier not only enhances their sense of belonging but is also an important part of the website's content monetization strategy.As an experienced website operation expert, I know the importance of accurately identifying user identity and flexibly displaying content in templates.

2025-11-06

How to determine whether a site has multilingual versions and display a language switch button using the `tag-languages` multilingual site tag?

AnQi CMS, as a Go language system deeply rooted in the field of enterprise-level content management, its powerful multilingual support is undoubtedly one of the core advantages to help enterprises expand into the global market.How can we intelligently determine whether a website is configured with multiple language versions and elegantly display language switch buttons when building websites for global users, which is a common problem encountered by content operation experts in template design.Today, let's delve into the `tag-languages` tag of Anqi CMS together, uncovering the mysteries of language switching.###

2025-11-06

How to display the image gallery based on whether there is an album in the `Images` field of `archiveDetail` or `pageDetail`?

## How to cleverly use Anqi CMS: intelligently judge and display image galleries in articles/pages As a senior website operation expert, I deeply understand the importance of content display for user experience and website attractiveness.In AnQiCMS (AnQiCMS) such an efficient and customizable content management system, how to flexibly present image content, especially dynamically displaying the image gallery based on whether there is an album, is a focus for many operators.

2025-11-06

How to determine whether the current page is the homepage, category page, detail page, or single page, and load the corresponding SEO information?

As an experienced website operations expert, I am well aware of the importance of Search Engine Optimization (SEO) in the increasingly fierce online environment.To do SEO well, the primary task is to ensure that every page of the website provides clear and accurate metadata to search engines.How can one determine the current page type (home page, category page, detail page, single page, etc.) and load the corresponding SEO information, which is a core issue often encountered by many operators and developers.Today, let's delve into the intelligent design and practical strategies of AnQiCMS (AnQiCMS) in this aspect

2025-11-06

How to determine if the document list under a specified tag is empty?

AnQi CMS, as an enterprise-level content management system built with Go language, has always been committed to providing users with efficient, customizable, and secure content operation solutions.In our daily content management work, especially when building dynamic, intelligent websites, we often need to flexibly adjust the display of the page based on the presence or absence of content.Today, let's delve deeply into a very practical and elegant feature of Anqi CMS - how to use the `tag-tagDataList` tag to determine if the document list under a specified tag is empty.In AnQi CMS

2025-11-06

How to determine if the `Logo` field of `tagDetail` exists to display the cover image of the label?

As an experienced website operations expert, I know that how to flexibly and elegantly handle content display is the key to improving user experience and the professionalism of the website.Today, let's talk about how to cleverly judge whether the `Logo` field exists in the tag details of AnQiCMS (AnQiCMS), and decide whether to display the cover image of the tag.This is not just a technical implementation issue, but also about how we make the tabs more attractive.### Label cover image: The highlight of content operation In AnQi CMS

2025-11-06

How to conditionally use the `cycle` tag to alternate CSS classes within a `for` loop?

## How to conditionally use the `cycle` tag elegantly in the `for` loop of AnQiCMS?In website content display, especially on list pages, we often hope to enhance user experience and information readability through visual differences.For example, list rows alternate with different background colors, or certain types of list items require special styles to highlight.As an experienced website operations expert, I am well aware of the efficient and flexible content management system in AnQiCMS

2025-11-06

How to determine the relationship between the current time and the document publishing time in the AnQiCMS template, and display "New" or "Expired"?

## Content时效性:How to intelligently display “New Release” and “Expired” in AnQiCMS template In the ever-changing world of the Internet, the 'freshness' and 'timeliness' of content are key to attracting and retaining visitors on the website.As an experienced website operation expert, I am well aware of the powerful features of AnQiCMS (AnQi Content Management System), which not only provides flexible content management capabilities but also endows content with infinite display possibilities through its powerful template engine.Today, we will delve into how to use the AnQiCMS template

2025-11-06