How to judge whether a custom field exists in the AnQiCMS template and conditionally render according to its value?

Calendar 👁️ 68

In AnQiCMS template development, flexibly displaying content is the key to improving user experience and website professionalism.Among these, the judgment of custom fields and conditional rendering according to their values is an indispensable skill to achieve this goal.In this way, you can ensure the accurate display of page content, avoid displaying empty values, or dynamically adjust the page layout and functionality based on specific data.

Understand AnQiCMS custom fields and their retrieval methods in templates

AnQiCMS is a powerful content management system, one of its core features is the 'flexible content model'.This means you can add various custom fields for different content (such as articles, products, etc.)For example, add fields such as "Product Color", "Size", "Stock Quantity", etc. to the product model, or add "Author" to the article model.

Related articles

How to skip certain items in the `for` loop of the AnQiCMS template based on specific conditions?

In AnQiCMS template development, we often need to display a series of contents, such as article lists, product lists, or navigation menus.But often, we do not want to display all the data at once, but rather hope to skip a part of it according to certain specific conditions, making the final content displayed more accurate and in line with the user's needs.AnQiCMS uses a syntax similar to the Django template engine, which provides a powerful and flexible tool for us to implement this conditional skipping.To implement `for`

2025-11-09

How to implement the `cycle` tag to alternate the display of different styles or data in AnQiCMS templates?

AnQiCMS provides many practical tags for template development, making content display more flexible and efficient.Among them, the `cycle` tag is such a clever tool that it can help us achieve the alternation of data or styles in loops, making the page content more dynamic and visually attractive. ### Understanding the `cycle` tag: Sequence controller in loops In web design, we often encounter situations where we need to apply different styles to repeating elements or display different types of data in a specific order. For example

2025-11-09

How to judge whether the current item is the first or last item in the `for` loop in AnQiCMS template?

In AnQiCMS template development, we often encounter situations where we need to display data in a list loop, such as article lists, product categories, navigation menus, etc.In these loops, sometimes we need to treat the first or last item in the list specially, such as adding unique CSS styles, displaying different content, or cleverly handling the separators between list items.AnQiCMS uses a syntax similar to the Django template engine, providing us with a very intuitive and powerful tool to solve these common template logic problems.### Core Mechanism

2025-11-09

How to check if the article content in the AnQiCMS template contains specific keywords and display conditions based on this?

In website content operation, we often need to flexibly adjust the display of the page according to the actual content of the article.For example, if an article mentions a specific product or event, we may want to highlight related purchase links or promotional information on the page;If the content of the article involves sensitive topics, it may be necessary to add additional disclaimers.This requirement for conditional display based on article content can be fully realized in the AnQiCMS template.AnQi CMS uses a template engine syntax similar to Django

2025-11-09

How to determine if the `Content` field of the document is empty using the `archiveDetail` tag and display alternative content?

How can you elegantly handle the case where the document content is empty in AnQi CMS?During the operation of the website, we often publish various types of documents, which contain important information.However, sometimes for various reasons, such as the content is still in draft stage, data is missing during import, or simply some documents are only titled without detailed text, we may encounter the situation where the `Content` field of the document is empty.If the template does not perform any processing when rendering these document detail pages, the user may see a blank page area, which not only affects user experience

2025-11-09

How to safely embed third-party statistics or advertising JS code in AnQiCMS templates?

In website operation, we often need to rely on third-party statistical tools to analyze visitor behavior, or to generate income through advertising platforms.Embed these third-party JavaScript (JS) codes securely and efficiently into website templates is a skill that every website operator needs to master.For those using AnQiCMS, understanding its template mechanism and built-in features can help us complete this task more securely.AnQiCMS is an enterprise-level content management system developed based on the Go language, which has always paid close attention to performance and security in its initial design

2025-11-09

How to ensure the correct setting of the `hreflang` tag in the `languages` label of the AnQiCMS multilingual site?

Today, with the deepening of globalization, many enterprises and content operators need to provide customized content for users of different languages or regions.To ensure that these multilingual versions can be correctly identified and displayed to target users, the proper setting of the `hreflang` tag is particularly important.For friends using AnQiCMS to build multilingual websites, the built-in `languages` tag is the powerful tool to solve this problem.Understanding the importance of the `hreflang` tag To delve deeper into

2025-11-09

How to judge whether an array or string is empty in AnQiCMS template using the `length` filter?

In Anqi CMS template development, we often need to decide the display content of the page based on the existence or absence of data, for example, a list of articles. If the list is empty, we may need to display "No content" instead of a blank area.At this time, the `length` filter becomes our powerful assistant, which can help us easily judge whether arrays, strings, and other data are empty.### Getting to know the `length` filter The `length` filter is a very practical feature provided by the Anqi CMS template engine

2025-11-09