In today's increasingly diversified content marketing era, 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 corporate or self-media operators, such as publishing event notifications, job openings, case studies, or industry reports.This, the custom content model feature provided by AnQiCMS, has become a powerful tool for us to flexibly manage and display these diversified information.
Content model, as the name implies, is a structural blueprint of content.It defines what fields are included in a category of information, the type of each field, and how these pieces of information are organized.Auto CMS knows the importance of this flexibility for content operation, and therefore integrated a highly customizable content model mechanism from the very beginning of system design.This is like providing you with a set of Lego blocks, allowing you to build various shapes of content containers based on your creativity and business logic, so that your website is no longer restricted by traditional content frameworks.
Build a dedicated content structure: The secrets of custom content models
In the 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 backend.The system is pre-installed with the 'Article Model' and 'Product Model' as basic models, which can serve as a starting point for you to get started quickly, and can also be modified according to your needs.However, the true power lies in creating a completely new model that conforms to 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 display key information such as event time, location, and participation limit.It is particularly necessary to customize an 'activity model' at this time.
When creating a new model, you need to set the following core properties:
- Model name:This is the Chinese name displayed 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.In order to ensure the stability and standardization of the system, it must use English lowercase letters.
activity. - URL Alias:Used to generate friendly URL addresses, usually in English lowercase letters, such as
event. 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
Core charm lies here: Flexible configuration of custom fields
After completing the basic model settings, the next step is to customize the fields, which is the core of the content model's flexibility.You can add unique fields for each model to accurately capture and manage the specific attributes of this type of content.
Continuing with the example of "Event Model", you can add the following fields to complete the event information:
- Parameter name:This is the Chinese display name of the field, for example, 'Activity Date', 'Activity Location', 'Registration Deadline', 'Activity Leader'.
- Field call:This is the English identifier used when calling this field in the template, it is also recommended to use lowercase letters, for example
event_date/location/deadline/organizer. - Field Type:Auto CMS provides various field types to meet different data storage needs:
- Single-line text:Suitable for brief text information, such as “Event Location”.
- Numbers:Applicable to pure numeric information, such as 'Maximum number of participants'.
- Multi-line text:Applicable to longer descriptive text, such as 'Activity details'.
- Single choice, multiple choice, dropdown selection:Applicable to preset option selection, such as "Activity TypeYou can enter option content one per line in the default value.
- Mandatory:Set whether this field is required to be filled in.
- Default value:Set an initial value for the field to improve the efficiency of content publishing.
By this method, you not only create a dedicated data structure for 'Activity Information', ensuring that each activity information is complete and standardized, but also greatly improve the efficiency of content management.Similarly, for the "Job Posting
The connection between content and the model: collaboration between categories and documents
In the AnQi CMS, there is a close hierarchical relationship between content models, 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 model belonging to that category.
This means that when you create or edit a category under "Content ManagementAfter you publish a new document under this category, the system will automatically present all the custom fields in the "Activity Model", allowing you to fill in complete activity information according to the preset structure.This design ensures the consistency of the content structure, avoiding the omission or confusion of information.
Display custom content flexibly in the front-end template
The ultimate purpose of the content model customization is to display this information in a clear and beautiful way on the website front-end.The Anqi CMS is based on the Django template engine syntax, providing rich template tags that allow you to easily display data from models 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 play a big role. You can specify which document list of content models to retrieve by using parameters, andmoduleIdcombine with,archiveParamsLabel, dynamically retrieve and display each content's custom field in a loop.
For example, you can call it like this on a list page of events.
{% 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 custom fields of the model are many, or you want to handle these fields more universally,archiveParamsTags 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