How to flexibly display different content types on the front-end page after customizing the content model?

Calendar 👁️ 75

In modern website operations, the diversity and personalized display of content are key to attracting users and enhancing brand image.AnQiCMS (AnQiCMS) with its flexible content model design, has brought unprecedented freedom to website content management.How to beautifully present the content with unique structure on the front page after customizing the content model according to business requirements, is a core skill that every operator needs to master.

Understanding the content model and flexible foundation of Anqi CMS

One of the core advantages of Anqi CMS is that it provides the 'flexible content model' feature.This means we are no longer limited to traditional 'article' or 'product' concepts, but can define any content type we want based on actual business scenarios.For example, you can create a "course" model to manage online learning materials, a "property" model to display real estate information, or a "team member" model to introduce company employees.

When creating these custom content models, you can add various 'custom fields' as needed.These fields are like the skeleton of content, which can be simple single-line text, numbers, or more complex image groups, multi-line text editors, as well as dropdown selections, radio buttons, or checkboxes.These custom fields give the content model a unique structure and rich data dimensions.For example, a "course" model can have fields such as "course name

This highly customizable content structure is the foundation for the flexible front-end display of Anqi CMS.It ensures that the data stored on the backend matches our expected frontend presentation.

The magic of front-end templates: an introduction to Django syntax

The front-end display of Anqi CMS benefits from its powerful Django-like template engine. It uses.htmlThe file acts as a template and provides an intuitive syntax, making it easy for users who do not understand complex programming to get started.

In the template file, we mainly encounter two types of syntax structures:

  1. double curly braces{{变量}}This is used to output the content of the variable. For example,{{archive.Title}}It will directly display the title of the current content.
  2. single curly braces and percent signs{% 标签 %}This is used to perform logical operations, such as conditional judgments, loop traversals, or calling specific function tags. For example,{% if condition %}is used for judgment,{% for item in list %}is used for loops.

All template files are stored in a unified location/templateUnder the directory, and the template engine supports UTF8 encoding, ensuring the correct display of content.

Core strategy: the combination of general and customized templates

In order to flexibly display different content structures, Anqi CMS provides a powerful template naming and calling mechanism.We can choose to use a general template, or specify a dedicated template for a specific content type or individual content item.

  • The default conventions of the general template: AnQi CMS will match the model模型tablename automatically and match the corresponding template file. For example, a model namedarticlewill usually look for the content list pagearticle/list.htmland the detail page will look forarticle/detail.html. The category list page will search for{模型table}/list-{分类id}.htmlwhile a single page can be bypage/{单页面id}.htmlCustomize. This means that for all content under a certain content model, as long as their structure is similar, they can share a set of common templates, greatly reducing the workload of repeated development.

  • Fine control of customized templatesWhen encountering special content that requires a layout completely different from the general template, Anqi CMS also provides a solution.For example, a specific 'download' article may require a detailed page with a download button, version information, and special layout.download.htmlThen fill in the document template field in the editing interface of the article (in the "Other Parameters" section), filedownload.html.This article will be displayed first using this customized template, while other articles will continue to use the default general template.This mechanism also applies to category pages and single pages, which can be realized by setting up "category template" or "single page template" in the background.

Flexible display of custom field content

Custom fields are the core of the content model, and displaying their content on the front end is crucial. Anqi CMS provides two main methods to retrieve and display these custom fields:

  1. Direct pass.archiveDetailtag to obtainIf your content model has a field namedauthoryou can use it directly in the detail page template{% archiveDetail with name="author" %}To get its value. This method is concise and clear, suitable for when you know exactly which custom field to display.
  2. ByarchiveParamsLoop through all custom fields with tags.Sometimes, we may be unsure of what custom fields the content model has, or we may want to dynamically display all custom fields and their values, for example, listing all product specifications on a product detail page. At this point,{% archiveParams params %}{% for item in params %}{{item.Name}}:{{item.Value}}{% endfor %}{% endarchiveParams %}It is very useful. It will traverse all the custom fields defined in the content model and output their names and corresponding values. Throughsorted=trueParameter, you can also ensure that the fields are displayed in the order defined by the backend.

For example, if your 'product' model defines custom fields such as 'material', 'color', 'size', etc., you can display them like this on the product detail page template:

{# 假设这是产品详情页模板 product/detail.html #}
<div class="product-info">
    <h1>{{archive.Title}}</h1> {# 产品标题 #}
    <img src="{{archive.Logo}}" alt="{{archive.Title}}"> {# 产品主图 #}

    <div class="product-specs">
        <h2>产品参数</h2>
        {% archiveParams params %}
        <ul>
            {% for item in params %}
                {# 排除一些内部字段或不需要展示的字段 #}
                {% if item.FieldName != 'price' and item.FieldName != 'stock' %}
                <li>
                    <strong>{{item.Name}}:</strong>
                    <span>{{item.Value}}</span>
                </li>
                {% endif %}
            {% endfor %}
        </ul>
        {% endarchiveParams %}
    </div>

    <div class="product-description">
        <h2>产品详情</h2>
        {# archive.Content是富文本内容,使用safe过滤器防止HTML转义 #}
        {{archive.Content|safe}}
    </div>
</div>

In this example,archive.Titleandarchive.LogoIs an Anqi CMS built-in field, while the "Product Parameters" section is througharchiveParamsDynamically displays all custom product specifications.

Scenario-based application: display cases of different content types

  • Article detail page: A typical article detail page may include title, publication time, category, tags, and body. In addition to built-in fields, you may also have a custom "article source" field.

    <h1>{{archive.Title}}</h1>
    <p>发布于:{{stampToDate(archive.CreatedTime, "2006-01-02")}} |
       分类:<a href="{{category.Link}}">{{category.Title}}</a> |
       来源:{% archiveDetail with name="source" %}</p>
    <div class="article-content">{{archive.Content|safe}}</div>
    

    here,stampToDateThe filter is used to format timestamps,category.Linkandcategory.Titlethen through built-in archive.Categoryobject to get the current article's category information.

  • Product list pageIf you have a "product" model, the list page may need to display product images, names, prices, and a custom "main selling point" field.

    {% archiveList products with type="page" moduleId="2" limit="10" %}
        {% for product in products %}
            <div class="product-card">
                <a href="{{product.Link}}">
                    <img src="{{product.Thumb}}" alt="{{product.Title}}">
                    <h3>{{product.Title}}</h3>
                    <p class="price">¥ {% archiveDetail with name="price" id=product.Id %}</p>
                    <p class="selling-point">{% archiveDetail with name="selling_point" id=product.Id %}</p>
                </a>
            </div>
        {% endfor %}
        {% pagination pages with show="5" %} {# 展示分页 #}
    {% endarchiveList %}
    

    In this example,archiveListGet the product list and byproduct.IdCombinearchiveDetailGet the custom price and selling points fields for each product.

  • single pageFor the "About Us" page, in addition to the regular content, you may also want to display a background image (custom field `

Related articles

How to manage and present the content of multiple independent brand websites in AnQiCMS in a unified manner?

In the current digital age, the need for enterprises or content operators to manage multiple independent brand websites is increasingly common.Each brand may have a unique style, product line, or target audience, but how to efficiently manage these contents under a unified framework, achieve centralized display under specific scenarios, while maintaining the independence of each brand, is a challenge faced by many teams.AnQiCMS as an enterprise-level content management system, its multi-site management function provides a powerful solution for this.One of the design初衷 of AnQiCMS is to serve users with multi-site management needs

2025-11-08

How does AnQiCMS ensure that website content displays perfectly on different devices?

In the digital age, website content can seamlessly adapt to various devices, from large desktop monitors to small smartphone screens, and is no longer an option, but the cornerstone of success.The user expects to have a smooth, beautiful, and fully functional experience regardless of which device is accessed.AnQiCMS as a product designed for efficient content management, provides a series of powerful and flexible features to ensure that your website displays content perfectly on any screen, making it shine on any screen.### AnQiCMS's multi-dimensional adaptive strategy AnQiCMS

2025-11-08

How does the `wordwrap` filter automatically wrap long text to a specified length

In the daily operation of websites, we often encounter such situations: the content of the article is too long, or the text extracted from other places has not been formatted, resulting in the text content exceeding the container width when displayed on the web page, destroying the overall layout and seriously affecting the reading experience of users.Especially on mobile devices, long lines of text are more difficult to read.To solve this problem, Anqi CMS provides a very practical tool - the `wordwrap` filter, which can help us automatically wrap long text to the specified length, thereby optimizing the display effect of the content

2025-11-08

How to calculate the number of words in a string with the `wordcount` filter in Anqi CMS template?

When processing text content in the AnQi CMS template, we often need to perform various operations on strings, such as counting words, cutting content, and so on.Among them, calculating the number of words in a string is a common requirement, which is very useful in content analysis, SEO optimization, and even estimating the reading time of an article.AnQi CMS provides a simple and powerful tool——`wordcount` filter.### `wordcount` filter: Core functionality and purpose The `wordcount` filter is specifically used to count the number of words in a given string

2025-11-08

How to implement the language support feature of AnQiCMS for content switching and correct display?

## Unlock Global Audience: How AnQiCMS Achieves Multi-language Content Switching and Accurate Display Under the wave of globalization, websites are no longer aimed at users in a single region.Whether it is to expand the international market, serve diverse cultural groups, or enhance brand influence, multilingual support has become an indispensable ability for modern websites.AnQiCMS as an efficient content management system, deeply understands this, and provides a flexible and practical multilingual solution to help users easily switch and display content in different language versions. AnQiCMS

2025-11-08

How to optimize URL structure through pseudo-static configuration to improve the display of content in search results?

How to optimize URL structure through pseudo-static configuration to enhance the display of content in search results?In website operations, a clear and meaningful URL structure is crucial for improving search engine visibility and user experience.It not only helps search engines better understand the content of the page, thus affecting the efficiency of crawling and indexing, but also allows users to identify the theme of the page at a glance in the search results, enhancing the willingness to click.AnQiCMS is a fully functional content management system that provides powerful static configuration functions, allowing users to easily create SEO-friendly URL structures

2025-11-08

How does AnQiCMS's advanced SEO tool help website content achieve higher visibility in search engines?

In today's highly competitive internet environment, the visibility of website content directly determines whether it can reach the target users.For operators, how to make their website occupy a favorable position in search engine results is a question they think about every day.AnQiCMS as a practical content management system provides a variety of advanced SEO tools to help users effectively improve the performance of their website content in search engines.Firstly, the basic optimization of the website cannot do without precise control of the content metadata.

2025-11-08

How does the Sitemap generation feature ensure that all website content can be discovered and displayed by search engines?

In today's highly competitive online environment, ensuring that every piece of content on the website is discovered and indexed by search engines is the foundation for successful website operation.This not only concerns traffic, but also directly affects the brand's exposure and the conversion of business.AnQiCMS provides a series of powerful and practical functions in content operation, especially in SEO tools, among which the Sitemap generation function is a key tool to solve the problem of content discovery.We can imagine Sitemap as a customized website map tailored for search engine spiders

2025-11-08