AnQiCMS content management system provides us with powerful content management capabilities with its excellent flexibility and customizability.In the daily operation of websites, we often encounter situations where the standard "article" or "product" model cannot fully meet the needs of specific business scenarios.This is where the custom feature of AnQiCMS content model becomes particularly crucial, allowing us to build personalized content structures according to the unique needs of the website, thereby achieving more precise and expressive page content display.

Why do you need a custom content model?

Imagine if your website needs to publish "Recruitment InformationIf we rely solely on the inherent 'article' model, we may need to force these key pieces of information into the main text, or handle them in an irregular manner, which not only leads to chaos in backend management but also makes front-end display difficult and lacks structureization.

How to create or modify the content model in AnQiCMS?

The content model management interface of AnQiCMS is intuitive and easy to use, allowing us to easily define the skeleton of the content.

Firstly, you need to log in to the AnQiCMS backend and navigate to“Content Management”the menu under“Content Model”.Here, you will see the built-in "article model" and "product model".Of course, to meet more personalized needs, we can choose 'Add Model' to create a new content type.

When creating or modifying content models, there are several core configuration items that we need to consider carefully:

  1. Model name:This is the Chinese name used to identify the model on the background management interface, for example, “Recruitment Information”, “Course Model”. It is convenient for us to quickly differentiate between different types of content.
  2. Model Table Name:This is the table name for custom fields stored in the database by the model, which must use lowercase letters. Once set, it is generally not recommended to change it arbitrarily to avoid data problems.
  3. URL Alias:Used as an identifier in the front-end page URL, it is also recommended to use lowercase English letters.This is crucial for building SEO-friendly URL structures.jobsThen the front-end list page may be/jobs/list.html.
  4. Title Name:This is the prompt text in the main title input box when publishing content, such as 'Job Title', 'Course Title', which can better guide content editors to fill in the correct information.

Custom field: the key to personalized content

The core of the content model lies in its custom fields.On the model settings page, you can add various types of fields based on your actual needs. These fields will determine which information you need to fill in when publishing content, as well as which data the front-end can obtain and display.

Click 'Add field', you will need to configure the following key properties:

  • Parameter name:This is the display name of the field on the background content editing page, for example, "Position Location
  • Field call:This is the variable name used when calling this field in the front-end template, it must be in English letters, and it is recommended to use camel case naming method (such asjobLocation)。This name will directly determine how you retrieve the data for this field in the template.
  • Field Type:AnQiCMS provides various field types to accommodate different data formats:
    • Single-line text:Suitable for short text inputs, such as contact information, job titles.
    • Numbers:Suitable for pure numeric inputs, such as prices, quantities.
    • Multi-line text:Suitable for longer text content, such as job descriptions, course introductions.
    • Single choice:Provide multiple options, but only one can be selected, such as 'Gender', 'Region'.
    • Multiple selection:Provide multiple options, allowing multiple selections, such as 'Skill Tags', 'Suitable Population'.
    • Dropdown selection:Similar to single choice, but presented in the form of a dropdown menu, suitable for situations with many options.
    • Choosing the appropriate field type can ensure the standardization and ease of use of data.
  • Mandatory:Tick the box to ensure that this field is filled in when publishing content, to ensure the completeness of key information.
  • Default value:You can set a default value for the field, or preset options for single-choice, multiple-choice, and dropdown selection fields.

By properly planning these custom fields, your content will have a clear structure, laying a solid foundation for subsequent personalized display.

Associate the content model with the content

In AnQiCMS, the association between content model and specific content isCategoryTo be implemented.Each category must belong to one and only one content model.This means that when you create a new category (such as "Front-end Development Positions") and specify it as the "Recruitment Information

When we enter the 'Publish Document' page and select a category belonging to a specific content model, the 'Other Parameters' section in the content editing area will automatically display all the custom fields defined by the content model, for the content editor to fill in.This dynamic adaptation mechanism greatly simplifies the content publishing process and avoids unnecessary field interference.

Realized in the front-end template to display personalized information

Completed the definition and publishing of the content model, the next step is how to display these structured contents in a personalized way on the website front-end.AnQiCMS uses a template engine syntax similar to Django, which makes template creation both powerful and flexible.

1. Conventions of template files and model-specific templates

AnQiCMS template creation follows certain conventions: template files are located/templateThe directory. For content models, AnQiCMS supports template files specific to models. For example, if you create a namedjobmodel table name:

  • Model list page:can createjob/list.htmlAs the list page template for all categories under this model.
  • Model details page:can createjob/detail.htmlAs the detail page template for all contents under this model. You can even specify an independent template file for specific categories or documents, for example.job/list-123.html(For the category list with ID 123) orjob/remote-jobs.html(Specify this template for a specific category or document in the background).

2. Call custom fields

In the template file, we can retrieve and display custom fields defined in the content model by using specific tags:

  • Directly call the content tag:InarchiveDetail(Document details) orarchiveListThe loop body of the (Document list) tag can directly access custom fields through dot notation. For example, if your custom field调用字段setjobLocation, you can use it directly in the template.{{item.JobLocation}}To display its value. "twig {% archiveDetail archive with name="Content" %} {# 获取当前文档的详情数据,并赋值给 archive 变量 #} <h3>{{archive.Title}}</h3> <p>职位地点:{{archive.JobLocation}}</p> {# 直接调用自定义字段JobLocation` #} <