How to customize the AnQiCMS content model to achieve personalized display of specific data on the front page?

Calendar 👁️ 62

In content operation, we often encounter such situations: the standard 'article' or 'product' content types cannot fully meet the diverse information display needs of the website.For example, a event page may need "registration deadline" and "event location", and a job information may need "position salary" and "work location", all of which are not possessed by traditional content models.At this moment, the flexible content model customization function of AnQiCMS (AnQiCMS) is particularly important, as it helps us easily build data structures that conform to specific business logic and presents them individually on the website front-end.

Understanding the importance of the content model

In Anqi CMS, the content model can be considered as the 'skeleton' of the website content, defining which fields and data types each content type (such as articles, products, events, recruitment, etc.) contains.The system provides default "article model" and "product model", but the real power lies in our ability to create or modify these models according to actual business needs, in order to precisely manage and display data of any type.This means that your website is no longer limited by predefined frameworks, but can be built entirely according to your imagination.

Step 1: Create or modify the content model

To start customization, first you need to enter the Anqie CMS backend management interface.Find the "Content Management" menu in the left navigation bar and then click on the "Content Model".This will list all existing content models, including system-built-in and custom ones.

If you want to create a completely new content type, such as "Recruitment Position" or "Course Information", you can click "Add New Model".If you want to add a field to an existing model (such as an article or product), click the 'Edit' button on the right side of the corresponding model.

In the model editing interface, you will see several core configuration items:

  • Model nameThis is the Chinese name displayed on the front and back end of the model, such as "Job Position", "Course".
  • Model table nameThis is the table name stored in the database for the model data, it must be in lowercase English letters and must be unique in all models, it is also an important identifier when calling data in the template.
  • URL alias: Used in static rule, represents the model in the URL path, and it is recommended to use lowercase letters in English.
  • Title NameThis will be used as the main title field prompt when you publish the model content, making it convenient for content editors to understand.

Step two: define custom fields to enrich the data structure

The next key step is to add custom fields to your content model for personalized display.At the bottom of the model editing page, there is a "Content Model Custom Field" area.Here, you can add various types of fields to store specific data.

Click "Add field", you need to configure the following items:

  • Parameter NameThis is the Chinese name displayed in the background editing interface, such as "Position Salary", "Location of Work", "Event Date".
  • Field invocationThis is the English name stored in the database for this field, which is also an important identifier used in the template to retrieve data. It is recommended to use camelCase or underscore naming conventions, such asjobSalary/workLocation/activityDateThis name must be unique and comply with programming specifications.
  • Field type: AnQi CMS provides various field types to adapt to different data formats:
    • Single-line text: Suitable for short text information, such as 'product model', 'author name'.
    • Number: Only input numbers, such as 'inventory quantity', 'product price'.
    • Multi-line textThis is applicable for long text descriptions, such as 'job description', 'event details'.
    • Single choice, multiple choice, dropdown choiceThese three types can preset multiple options for content editors to choose from in a list, commonly used for 'house types', 'gender', 'product color', etc.You need to enter an option per line in the "default value".
  • Mandatory?This determines whether the content editor must fill in this field when publishing.
  • Default value: Set a default value for the field. This is where all options are defined for selection fields.

By reasonably defining these custom fields, you can build precise data structures for different types of content, thus laying a solid foundation for front-end personalized display.

Third step: publish content, fill in custom data

After you have completed the definition of the content model and saved it, you can start publishing content of the corresponding type.Under "Content Management", select your custom model, click "Add Document" (or the button corresponding to your model name).

In the content publishing interface, in addition to the default fields such as title, content, and category, you will find a new 'Other Parameters' area at the bottom that you have defined in the model.All custom fields will be displayed here with the prompt name you set, waiting for you to fill in specific data.

Please note that each document must select a category it belongs to, and that category belongs to a content model.Only by selecting the corresponding category can the content model's unique custom fields be displayed and filled in correctly.

Fourth step: implement personalized display on the front-end page (template customization)

The data structure has been defined, the content has also been filled in, and the next most anticipated part is: how to make these customized data shine on the front page.The Anqi CMS adopts a syntax similar to the Django template engine, making template customization intuitive and powerful.

  1. Access the custom data of a single document

    When you are on the document details page, you can usearchiveobjects to access your custom fields. For example, if you have a namedjobSalarycalled field, you can use it directly in the template{{archive.JobSalary}}To display its content. Note that the field name is usually capitalized in the template.

    If you need to loop through all custom fields or the field name is uncertain, you can usearchiveParamsTags:

    {% archiveParams params %}
        <div>
            {% for item in params %}
            <div>
                <span>{{item.Name}}:</span>
                <span>{{item.Value}}</span>
            </div>
            {% endfor %}
        </div>
    {% endarchiveParams %}
    

    If your custom field stores rich text (which may contain HTML), be sure to add|safeA filter to prevent HTML from being escaped, or if the content is in Markdown format, you can use|renderA filter to render it as HTML:

    <div>职位描述:{{archive.JobDescription|safe}}</div>
    {# 如果是Markdown内容 #}
    <div>技术要求:{{archive.TechRequirements|render|safe}}</div>
    
  2. Access custom data in the list

    On the list page (such as the recruitment list, course list), you can usearchiveListtags to get the document list. WhenforLoop througharchivesor you define a variable, eachitemrepresents a document, you can also useitem.自定义字段名Come visit its custom data:

    {% archiveList archives with moduleId="您模型对应的ID" type="page" limit="10" %}
        {% for item in archives %}
        <div>
            <h3><a href="{{item.Link}}">{{item.Title}}</a></h3>
            <p>职位薪资:{{item.JobSalary}}</p>
            <p>工作地点:{{item.WorkLocation}}</p>
            {# 其他自定义字段... #}
        </div>
        {% endfor %}
    {% endarchiveList %}
    
  3. Filter content based on custom fields

    A more advanced usage is to allow visitors to filter content based on custom fields. Anqi CMS providesarchiveFiltersTo achieve this goal, for example, in the job listing, users can filter for 'full-time' or 'part-time' positions.

    First, you need to make sure that these custom fields are searchable in the content model configuration. Then, use it in the template like this:

    <div>
        <h3>职位筛选:</h3>
        {% archiveFilters filters with moduleId="您模型对应的ID" allText="不限" %}
            {% for item in filters %}
            <p>{{item.Name}}:</p>
            <ul>
                {% for val in item.Items %}
                <li class="{% if val.IsCurrent %}active{% endif %}"><a href="{{val.Link}}">{{val.Label}}</a></li>
                {% endfor %}
            </ul>
            {% endfor %}
        {% endarchiveFilters %}
    </div>
    

    This code will generate a set of filter options, which will automatically filter the content based on the selected custom field value when the user clicks.

  4. The relationship between model and template

    AnQi CMS also supports specifying different template files for different content models. By default, the system will try to find{模型表名}/detail.htmlas the detail page template, as well as{模型表名}/list.htmlas the list page template. For example,

Related articles

How to implement diversified display of articles, products, etc. in AnQiCMS templates?

When building modern websites, the way content is presented is crucial for attracting users, conveying information, and achieving operational goals.A good content management system should not only make content publishing simple but also make the presentation of content flexible and varied.AnQiCMS is providing strong support in this aspect, through its flexible content model, powerful template engine, and rich tag system, allowing articles, products, and various other content to be displayed in diverse forms to visitors.Flexible content model: Building a differentiated content structure AnQiCMS

2025-11-08

How to use single quotes, double quotes and

During the template development process of Anqi CMS, handling single quotes, double quotes, and other special characters in content is a common requirement, especially in ensuring the correct display of the page and preventing security issues.The Anqi CMS template engine (similar to Django syntax) provides a smart and secure mechanism when handling these characters, allowing us to flexibly control the display of content. ### The default behavior of the template: Security first Firstly, we need to understand a core design concept of the Anqi CMS template: **Security first**.This means

2025-11-08

How does the `add` filter flexibly handle different types of variables for addition in AnQiCMS?

In Anqi CMS, we often need to handle various data and present it flexibly to visitors.Whether it is a simple number calculation or complex text concatenation, I hope it can be completed with a simple and intuitive method.Today, let's delve deeply into a particularly practical template filter——`add`, which demonstrates excellent flexibility in handling variable addition, helping us build dynamic content more efficiently and intelligently.--- ### `add` filter: Template "addition art" `add`

2025-11-08

How to add two numbers or concatenate strings in AnQiCMS templates?

In AnQiCMS template design, dynamically handling data is a key element in building a feature-rich website.Whether it is to calculate the total price of goods or to concatenate user-friendly prompt information, the template engine provides a concise and efficient way to complete these tasks.This article will delve into how to implement the addition of numbers and the concatenation of strings in the AnQiCMS template, helping you better utilize the template features.

2025-11-08

How does AnQiCMS support the switching and display of multilingual content to meet global promotion needs?

Faced with an increasingly globalized market, how can a corporate website effectively reach users all over the world, and language barriers are the first challenges to overcome.AnQiCMS is well aware of this, and therefore, from the very beginning of the system design, it has made multilingual support one of its core features, aiming to help users easily achieve global promotion and display of content. ### How AnQiCMS Tackles Globalization Challenges: The Foundation of Multilingual Support AnQiCMS provides a simple and efficient solution that allows your website to be presented in multiple languages to global users. This means regardless of where your target audience is located

2025-11-08

How to configure the pseudo-static URL rules in AnQiCMS to optimize the display structure of website content links?

The importance of link structure in website operation is self-evident.A clear and meaningful URL not only enhances user experience, but also makes it easier for visitors to understand the content of the page, and is a key factor in Search Engine Optimization (SEO).Disorganized, dynamic URLs with a large number of parameters often make it difficult for search engine spiders to crawl and are not conducive to the transmission of keyword weights.Therefore, converting dynamic URLs to static forms is a common choice in modern website construction.AnQiCMS (AnQiCMS) knows this, built-in powerful static URL configuration function

2025-11-08

How do Sitemap, Robots.txt, and other advanced SEO tools in AnQiCMS affect the visibility of website content in search engines?

During the journey of website operation, we all hope that our content can be discovered by more potential users.And the search engine is undoubtedly the most important bridge connecting websites to users.To ensure that this bridge is unobstructed, our website needs to communicate effectively with search engines.

2025-11-08

How to customize the content display layout of the article detail page in AnQi CMS

AnQi CMS has excellent flexibility in content display, especially for article detail pages, it provides multi-level customization options, allowing us to finely control the layout of content display according to specific needs, whether it is for the entire model, specific categories, or an independent article.This not only involves adjustments in appearance, but also includes in-depth customization of the page content structure and information presentation.

2025-11-08