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.At this time, the content model customization feature of AnQiCMS is particularly crucial, as it allows us to build personalized content structures based on the unique needs of the website, thereby achieving more precise and expressive page content display.
Why do you need to customize the content model?
Imagine if your website needs to publish content such as "job information", "course schedule", "successful cases", or "project reports", etc., these contents often contain specific fields in addition to titles, content, and images, such as the job information may require "location of the position", "salary range", and "education requirements".The course schedule may require "class time", "instructor", "class hours", etc.If we rely solely on the inherent 'article' model, we may need to squeeze these key pieces of information into the main text, or use irregular methods to process them, which not only leads to chaos in backend management, but also makes the front-end display difficult and lacks structure.
The benefits of a customized content model lie in the fact that it can make your content management more refined and structured.By defining dedicated fields for different types of content, we can ensure data integrity and consistency, improve content management efficiency, and more importantly, provide rich and structured data sources for front-end pages to achieve highly personalized content display.
How to create or modify a 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.
First, you need to log in to the AnQiCMS backend and navigate to“Content Management”Under the menu“Content Model”. Here you will see the built-in 'article model' and 'product model'.Of course, to meet more personalized needs, we can choose to 'Add Model' to create a completely new content type.
When creating or modifying a content model, there are several core configuration items that we need to consider carefully:
- Model name:This is the Chinese name used to identify the model in the background management interface, for example, "Recruitment Information", "Course Model". It is convenient for us to quickly distinguish between different types of content.
- Model table name:This is the table name stored in the database for the custom field of the model, which must be in lowercase letters. Once set, it is generally not recommended to modify it arbitrarily to avoid data problems.
- URL alias:The identifier used in the front-end page URL, it is also recommended to use lowercase letters.This is crucial for building SEO-friendly URL structures.For example, the URL alias for a recruitment information can be
jobsThen the front-end list page may be/jobs/list.html. - Title Name:This is the prompt text for the main title input box when publishing content, such as 'Position Name', 'Course Title', which can better guide the content editor to fill in the correct information.
Custom field: The key to implementing 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 according to your actual needs, which will determine the information you need to fill in when publishing content, as well as the data that the front-end can obtain and display.
Click "Add field" and you will need to configure the following key properties:
- Parameter name:This is the background content editing page, the display name of this field, for example, "Position Location", "Salary Range". It should be clear and understandable.
- Call field:This is the variable name used when calling this field in the front-end template, it must be alphabetic, and it is recommended to use camel case (such as
jobLocationThis name will directly determine how you retrieve the data field in the template. - Field type:AnQiCMS provides various field types to adapt to different data formats:
- Single-line text:Suitable for short text input, such as contact information, job titles.
- Number:Suitable for numeric input, such as price, quantity.
- 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 that can be selected, such as 'Skill Tags', 'Suitable Audience'.
- Dropdown selection:Similar to single choice, but presented in the form of a dropdown menu, suitable for situations with many options.
- Choose an appropriate field type to ensure the standardization and ease of use of data.
- Mandatory?:Check this box, the field must be filled in when publishing content to ensure the completeness of key information.
- Default:You can set a default value for the field, or preset options for single-choice, multiple-choice, and drop-down selection fields.
By reasonably 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.
The association of content model with specific content is through AnQiCMSCategoryTo 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 Position") and specify it as the "Recruitment Information" model, all content published under this category will follow the field structure of the "Recruitment Information" model.
When we enter the 'Publish Document' page and select a category that belongs to a specific content model, the 'Other Parameters' section of 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, avoiding unnecessary field interference.
Individualized display is achieved in the front-end template
Completed the definition and release of the content model, and 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. The convention of template files and model-specific templates
AnQiCMS template creation follows certain conventions: the template files are located/templateUnder the directory. For the content model, AnQiCMS supports template files specific to the model. For example, if you create a model table namedjob: model table name
- Model list page:can create
job/list.htmlAs the list page template for all categories under this model. - Model detail page:can create
job/detail.htmlAs the detail page template for all content under this model. You can even specify an independent template file for a specific category or document, for examplejob/list-123.htmlOr for the category list with ID 123job/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 use specific tags to retrieve and display custom fields defined in the content model:
- Call through content tags directly:In
archiveDetailOr (document details)archiveList(Document list) In the loop body of the (Document list) tag, you can directly access custom fields using dot notation. For example, if your custom field调用字段is set tojobLocation, you can directly use it in the template.{{item.JobLocation}}Show its value. "twig {% archiveDetail archive with name="Content" %} {# 获取当前文档的详情数据,并赋值给 archive 变量 #} <h3>{{archive.Title}}</h3> <p>职位地点:{{archive.JobLocation}}</p> {# 直接调用自定义字段JobLocation` #} <