In today's increasingly diversified era of content marketing, the types of information that websites need to carry are also becoming richer.Relying solely on the general types of "articles" and "products" often fails to meet the personalized display needs of enterprises or self-media operators, such as posting event notifications, job openings, case studies, or industry reports.At this time, the customized content model feature provided by AnQiCMS (AnQiCMS) has become a powerful tool for us to flexibly manage and display this diversified information.

Content model, as the name implies, is a structural blueprint for content.It defines which fields a certain type of information contains, the type of each field, and how to organize these pieces of information.AnQi CMS knows the importance of this flexibility for content operation and therefore integrated a highly customizable content model mechanism from the beginning of system design.This is like providing you with a set of Lego blocks, where you can build various shapes of content containers according to your own creativity and business logic, allowing your website to break free from traditional content frameworks.

Set up a dedicated content structure: The mysteries of custom content models

In AnQi CMS, the process of customizing content models is intuitive and logical.You can find the 'Content Model' feature entry through the 'Content Management' module on the back end.The system is default built-in with 'Article Model' and 'Product Model' as two basic models, which can be used as a quick start point and also can be modified according to requirements.However, the true power lies in creating a completely new model that fits your business logic.

Assuming you need to publish a series of offline event information, the traditional "article" model may only have a title and content, which cannot clearly show the event time, location, number of participants, and other key information.At this time, it is particularly necessary to customize an 'activity model'.

When creating a new model, you need to set the following core properties:

  • Model name:This is the Chinese name that users see in the background, such as "Activity Information", "Job Positions". It should clearly describe the content type carried by the model.
  • Model table name:This is the table name used by the system to store the model data in the database.For the stability and standardization of the system, it must use English lowercase letters.For example, if you create a "event information" model, the table name can be set toactivity.
  • URL alias:Used to generate friendly URL addresses, usually in lowercase English letters, such asevent. This is crucial for SEO optimization and user experience.
  • Title Name:This is the prompt text for the main title of the content when publishing the model.For example, in the 'event model', you can set it to 'event topic' to make it clear to the content editor.

The core charm lies in the flexible configuration of custom fields

After completing the basic model settings, the next step is to customize the field, which is the core of the content model truly demonstrating its flexibility.You can add unique fields for each model to accurately capture and manage the specific attributes of this type of content.

Continue with the example of 'activity model', you can add the following fields to complete the activity information:

  • Parameter name:This is the display name of the field, such as 'Event Date', 'Event Location', 'Registration Deadline', 'Event Manager'.
  • Call field:this is the english identifier used when calling this field in the template, it is also recommended to use lowercase letters, for exampleevent_date/location/deadline/organizer.
  • Field type:Our company provides various field types for different data storage needs:
    • Single-line text:Suitable for short text information, such as "Event location".
    • Number:Applicable to pure numeric information, such as "Maximum number of participants."
    • Multi-line text:Applicable to longer descriptive text, such as "Event details."
    • Single choice, multiple choice, dropdown choice:A choice suitable for preset options, such as "activity type" (lecture, exhibition, salon), or "participant" (students, staff, everyone).You can enter options one per line in the default value.
  • Mandatory?:Set whether this field must be filled in.
  • Default:Set an initial value for the field to improve the efficiency of content publishing.

In this way, you not only create a dedicated data structure for "event information", ensuring that each event information is complete and standardized, but also greatly improve the efficiency of content management.Similarly, for the "Job Posting" model, you can set fields such as "Location", "Salary Range", "Education Requirements", and so on;For the "case study", you can set fields such as "client name", "industry field", "solve problems", etc.

Integration of content with the model: collaboration between categories and documents

In Anqi CMS, the content model has a close hierarchical relationship with categories and documents.Each category must belong to a specific content model, and each document you publish must first select a category and then inherit all the fields of the category model.

This means that when you create or edit a category under "Content Management", you need to associate it with the previously defined "activity model".After you publish a new document under this category, the system will automatically present all the custom fields in the "event model", allowing you to fill in complete event information according to the preset structure.This design ensures consistency in content structure, avoiding information omission or confusion.

Display custom content flexibly in the front-end template.

The ultimate purpose of content model customization is to display this information in a clear and beautiful way on the website front-end.The Anqi CMS based on the Django template engine syntax provides rich template tags, allowing you to easily display data from the model on the page.

When displaying a single content detail page,archiveDetailtags are your main tool. Through{{archive.你的调用字段名}}Or{% archiveDetail with name="你的调用字段名" %}you can directly call the value of a custom field. For example, to display 'event date', you can use{{archive.event_date}}.

If you want to display different types of custom content in a list form,archiveListtags will shine. You can use parameters to specify which document list of the content model you want to get, and combinemoduleIdthe parameters to combine the document lists of different content models.archiveParamsLabel, dynamically retrieve and display each content's custom field in a loop.

For example, you can call it like this on an event list page.

{% archiveList activities with moduleId="活动模型ID" type="page" limit="10" %}
    {% for activity in activities %}
    <div>
        <h3><a href="{{activity.Link}}">{{activity.Title}}</a></h3>
        {# 直接调用自定义字段,假设调用字段是 event_date, location #}
        <p>活动日期:{% archiveDetail with name="event_date" id=activity.Id %}</p>
        <p>活动地点:{% archiveDetail with name="location" id=activity.Id %}</p>
        <div>{{activity.Description}}</div>
    </div>
    {% endfor %}
{% endarchiveList %}

If the model has many custom fields, or you want to handle these fields more universally,archiveParamsThe tag can return all custom fields in an array format, making it convenient for you to iterate and display:

{% archiveList activities with moduleId="活动模型ID" type="page" limit="10" %}
    {% for activity in activities %}
    <div>
        <h3><a href="{{activity.Link}}">{{activity.Title}}</a></h3>
        {% archiveParams params with id=activity.Id %}
        {% for item in params %}
        <div>
            <span>{{item.Name}}:</span>
            <span>{{item.Value}}</span>
        </div>
        {% endfor %}
        {% endarchiveParams %}
        <div>{{activity.Description}}</div>
    </div>
    {% endfor %}
{% endarchiveList %}

In addition, if you want users