In website content operation, we often encounter situations where we need to display diversified information.Traditional CMS may only provide fixed 'article' or 'product' types, and when business requirements become more complex, such as when displaying real estate information, job openings, event schedules, etc., these fixed types often seem to be inadequate.At this moment, the flexible content model function of AnQiCMS is particularly important, as it allows us to tailor the data structure to meet specific business needs and present the content in the way we want on the front end.
1. Why do we need to customize the content model?
Imagine if your website not only had to publish press releases but also display various models of products or post job information as a recruitment platform.If all this diverse content is crammed into an 'article' model, it will be very chaotic to manage, the front-end display will also become complex, and the user experience will be greatly reduced.It is also difficult for search engines to understand the true intention of the content, affecting SEO performance.
The custom content model is designed to solve these problems. It allows you to define independent fields and properties for different types of content according to your actual business needs. For example:
- Real estate information:May require fields such as 'type', 'area', 'price', 'community', 'floor', 'picture set' and the like.
- Product details:May need fields such as 'Product Number', 'Brand', 'Specs', 'Detailed Pictures', 'Customer Reviews', etc.
- Job position:May require fields such as 'position name', 'salary range', 'work location', 'duties and responsibilities', 'requirements for position', etc.
In this way, each content type has its dedicated data structure, making backend management clearer and more efficient, and the frontend display can also achieve accurate matching, greatly enhancing the professionalism and user-friendliness of the website.AnQiCMS is one of its core advantages with its 'flexible content model', empowering operators to easily meet these challenges.
Chapter 2: Create and configure custom content models in AnQiCMS
Creating a custom content model in AnQiCMS is a straightforward and powerful process. It is mainly completed through the "Content Management" module in the backend.
1. Define your content model
Firstly, we need to log in to the AnQiCMS backend and navigate to the 'Content Management' option under 'Content Model'.Here, you can see the default 'article model' and 'product model' of the system.To create a new content model, we can choose to 'add model' or directly modify an existing model to meet a wider range of needs.
Several key items need to be carefully filled in when defining the model:
- Model name:This is the Chinese name identified by the model in the background, for example, "Real Estate Information", "Recruitment Position".
- Model table name:This is very important, it is the table name where the model data is stored in the database, it must beEnglish lowercase letters. It is also used when calling the model content in the front-end template
moduleIdThe parameter'stokenIt can be used as the basis for folder names in the template path, for examplehouse_listingorjob_post. - URL alias:It is used for the composition of pseudo-static URLs, it is recommended to useEnglish lowercase lettersThis is convenient for SEO and user memory.
- Title Name:This is the prompt text for the main title field when publishing content, for example, changing 'Article Title' to 'Property Name' or 'Position Name'.
2. Add model-specific custom fields
The core function lies in "custom content model fields". Here you can add any unique fields you need for your new model. Click "Add field" to set:
- Parameter name:This is the Chinese prompt displayed next to the field when editing content in the background, for example, 'House type', 'Salary', 'Event date'.
- Call field:This is the variable name used when calling the field content in the front-end template, it must beEnglish letters. For example, if the parameter name is "house type", the field to be called can be
houseType. This field name will be used directly in the template to retrieve data. - Field type:AnQiCMS provides various field types to adapt to different data storage needs, including:
- Single-line text:Applicable for short texts, such as titles and abbreviations.
- Number:Applicable for prices, quantities, areas, etc.
- Multi-line text:Applicable for descriptions, details, etc. of longer texts.
- Single choice/Multiple choice/Dropdown choice:Applicable for predefined options, such as 'Apartment (One bedroom, Two bedrooms)', 'Education (Bachelor, Master)'. Define each option by entering it in the 'Default Value' field.
- Mandatory?:Set whether the field is required according to business needs.
- Default:Provide an initial value for the field, especially the option list for selection type fields.
Carefully design these fields, as they will directly affect the degree of structuring of your content and the flexibility of front-end display.
3. Associate content with the model: Classification and document publication
After creating a custom content model, the next step is to associate actual content with it.
- Create categories:In the 'Content Management' under 'Document Category', when you add a new top-level category, you can select its 'Document Model'.Select the custom model you just created, then all the contents under this category will follow the field structure of this model.
- Publish content:When you publish a new document under the corresponding model category (such as "Add Document"), you will find that in addition to the conventional fields such as title, introduction, and content, the page will automatically display all the fields you have customized for the model.The editor only needs to fill in the data according to the prompts.
Up to this point, your business data has been entered into AnQiCMS according to a customized structure, and the next step is how to elegantly display this content on the website front end.
Three, elegantly display custom content in the front-end template
AnQiCMS uses Django template engine syntax, combining its powerful template tags to make the display of custom content flexible and efficient.
1. Understand the template file conventions and structure
The template files of AnQiCMS are stored in/templatedirectory, each independent template set has its own subdirectory andconfig.jsonFile. To display the content of the custom model, we usually use the following conventions:
- Model list page:
{模型table}/index.htmlFor examplehouse_listing/index.html. - Model detail page:
{模型table}/detail.htmlFor examplehouse_listing/detail.html. - Static resources (CSS, JS, images, etc.) are placed in
/public/static/directory.
These naming conventions allow AnQiCMS to automatically recognize and apply the corresponding templates, saving us a lot of configuration work.
2. Display of list page content:archiveListwitharchiveFiltersTag
To be on the list page of a custom model (such ashouse_listing/index.html)