As a website operator who is deeply familiar with the security CMS, I know that flexible content management is the key to improving user experience and achieving personalized operation.The powerful function of Anqi CMS in customizing content models is the core weapon that allows us to freely respond to various business needs.Today, I will detail how to customize the content model in AnQiCMS to meet your personalized needs.
The core role of the content model in AnQiCMS
In AnQiCMS, the content model (Content Model) is the cornerstone for organizing and managing website content.It defines the structure and properties of a certain type of content, for example, an article should include title, author, publication date, etc., while a product may include product name, price, inventory information, etc.The AnQi CMS is default built-in with two general models: 'Article Model' and 'Product Model', which cover most of the basic content needs of websites.However, for specific industries or business scenarios, such as real estate websites needing 'property model', e-commerce platforms needing more detailed 'product model', educational institutions needing 'course model', and so on, these default models clearly cannot meet the needs of personalized data storage and display.
It is precisely to address this diverse content structure requirement that AnQiCMS provides highly flexible content model customization features.Through this feature, you can freely create and expand content types based on your business logic, ensuring that each piece of content is managed in the most fitting way according to its attributes, greatly enhancing the system's adaptability and content operation efficiency.
The value of flexible customization
The value of the customized content model is not just about storing more types of data.It directly relates to the professionalism of your website content, user experience, and future scalability.Imagine if you were running a used car trading platform and did not have a dedicated 'vehicle model'. You might need to stuff the vehicle's 'brand', 'model', 'mileage', 'displacement', and other key information into some general field or directly into the body of the text.This not only makes data management chaotic, but also makes it extremely difficult for front-end display, search filtering, and data statistics.
By customizing the content model, you can precisely define unique fields for each special content type.This way, content entry will be more standardized, and operation personnel can clearly see the purpose of each field; when displayed on the front-end, fine-grained layout and style control can be achieved based on custom fields; and when retrieving data, efficient filtering and querying can be performed based on specific fields.This refined content management will directly transform into a better user experience and more efficient operational processes.
Gradually create and define a personalized content model
To start customizing your content model, you first need to enter the AnQiCMS backend management interface.
You can find the 'Content Management' module in the left navigation bar on the back end, click to enter, and you will see the 'Content Model' option. This is the central hub for managing all content models.
On the content model management page, you will see the system built-in 'article model' and 'product model'.To create a brand new custom model, you need to click on the corresponding 'Add Model' button.
When creating a new model, you need to fill in some basic information:
- Model nameThis is the Chinese name you identify the model in the background management interface, for example, 'Real Estate', 'Course', 'Recruitment Position', etc. It is used for user interface display and navigation in the background.
- Model table nameThis is a key internal identifier that defines the table name in which the model's content data is stored in the database. The name must bein English lowercase lettersAnd it is unique in the system. For example, if you create a "property model", the table name of the model can be set as
house_listingPlease note that once set, it is not recommended to make arbitrary changes to avoid data confusion. - URL aliasThis field is used for the composition of the frontend URL of your website, usually displayed in pseudo-static rules. It must also bein English lowercase letters, and concise. For example, the property model can use
houseAs a URL alias, the URL of the related page may contain/house/. - Title nameThis is the prompt text for the content title when you publish the model content.For example, when creating a "product model", you can set it as "product name", so that when publishing a product, the title field will display "product name" as a prompt.
After completing the basic information, the next step is to define the exclusive fields of the model.This is the core of implementing personalized content.On the model editing or adding page, there will be a section called 'Content Model Custom Fields'.
- Parameter nameThis is the display name of the field in the background management interface, which is convenient for operators to understand and fill in, such as 'number of bedrooms', 'duration of courses', 'workplace', and so on.
- Call fieldThis is the unique identifier you use to call the field data in the template. It must bein English lowercase lettersand is unique within a model. For example, the field name for 'number of bedrooms' could be
bedrooms,“course duration” could beduration. - field typeAnQiCMS provides various field types to adapt to different data formats.
- Single Line TextIt is suitable for short text input, such as names, titles, short descriptions, etc.
- NumberOnly numbers are allowed, applicable to price, quantity, area, etc.
- Multi-line textApplicable to long text input, such as detailed introduction, notes, etc.
- Single selectionProvide preset options for users to select one, such as "Gender" (Male, Female), "House Type" (Apartment, Villa).Options are entered one by one through the "Default Value" field.
- Multiple selectionProvide preset options, allowing users to select multiple at the same time, such as 'House Features' (furnished, with a balcony, close to subway).Options values should be entered one per line in the "Default Value" field.
- Drop-down selectionSimilar to single choice, but presented in a dropdown menu format, saving page space, suitable for situations with many options, such as 'cities', 'provinces'.Enter option values one per line in the 'Default Value' field.
- Is requiredYou can specify whether this field is required to be filled in when the content is published.
- Default valueSet a default value for the field. For radio, checkbox, and dropdown selection types, this is where you define all options, one per line.
For example, to create a "property model", we can define the fields like this:
- Model Name: Property
- Model Table Name:
property_listing - URL Alias:
house - Title Name: Property Title
Custom field:
- Parameter name: bedroom count, called field:
bedrooms, field type: numeric - Parameter name: bathroom count, called field:
bathrooms, field type: numeric - Parameter name: Floor Area (Square Feet), Field called:
area_sqft, field type: numeric - Parameter name: Property Type, Field called:
property_typeField type: Dropdown selection, default value: Apartment Villa Townhouse - Parameter name: Price, field called:
price, field type: numeric - Parameter name: Address, field called:
addressComma field type: Single line text
Through such a definition, our "house model" has highly structured proprietary data fields.
Using custom models in content publishing
When you define and save a new content model, these custom fields will appear under 'Add Document' or 'Document Category' pages under 'Content Management'.
When adding a document, you first need to select the 'category' to which the content belongs.It should be noted that each category must and can only be bound to one content model.When you select a category bound to a custom model, the 'Other Parameters' collapsible box on the page will dynamically display all the custom fields of the model for you to fill in according to the actual content.For example, if you select the 'Listing' category, you can fill in exclusive information such as the number of bedrooms, bathrooms, address, and sale price in the backend.
Display custom data in front-end templates
The most important part of the custom model is how to display these personalized data on the website's front-end template.AnQiCMS powerful template tag system makes this process intuitive.
When you arearchiveDetail(Document details) orarchiveListthe custom fields of the model will be used when getting content data in the (Document list) tagitemUse the property of 【en】to use.
To display a specific custom field, you can access it directly using dot notation, for example, to display 'Number of Bedrooms':{{item.bedrooms}}(In list loop){% archiveDetail with name="bedrooms" %}(In detail page)
You can use it to display a list of all custom fields (for example, for product parameter tables) if you wisharchiveParamsTags. It allows you to traverse all custom parameters of the model:.
{% archiveParams params %}
<div>
{% for item in params %}
<div>
<span>{{item.Name}}:</span>
<span>{{item.Value}}</span>
</div>
{% endfor %}
</div>
{% endarchiveParams %}
This code will output the 'parameter name' and corresponding 'parameter value' of each custom field.
In addition,archiveFiltersThe tag provides the function to filter content on the front end according to custom fields.This is very useful for implementing complex search or classification filter pages.For example, users can filter the list of listings by 'Property Type' or 'Number of Bedrooms'.
{# 参数筛选代码,结合archiveList分页列表使用 #}
<div>
<div>房源筛选条件:</div>
{% archiveFilters filters with moduleId="您的房源模型ID" allText="不限" %}
{% for item in filters %}
<ul>
<li>{{item.Name}}: </li>
{% for val in item.Items %}
<li class="{% if val.IsCurrent %}active{% endif %}"><a href="{{val.Link}}">{{val.Label}}</a></li>
{% endfor %}
</ul>
{% endfor %}
{% endarchiveFilters %}
</div>
By combining these tags, you can flexibly display the data from your customized model on any page, achieving highly personalized content presentation.
**Practical Tips and Considerations
When customizing content models, there are several **principles** to keep in mind:
- Plan aheadBefore creating models and fields, please make sure to plan your content types and required fields in detail. Clear planning can avoid unnecessary modifications and data migration work later on.
- Field naming specificationThe 'model table name' and the 'field name' of custom fields are recommended to use lowercase letters and underscores (snake_case) for naming, for example:
house_listingorarea_sqftThis helps maintain code consistency and avoid potential conflicts. - Choose field types reasonably.Select the most appropriate field type based on the actual data type (for example, use a numeric type for price instead of text), which not only ensures data accuracy but also facilitates subsequent data processing and calculations.
- SEO-friendlyWhen customizing the URL alias, choose descriptive and short English words, which is very helpful for search engine optimization (SEO).
- Performance considerationsAlthough the Go language foundation of AnQiCMS ensures high performance, overly complex models or a large number of custom fields may still have a slight impact on database performance.In design, the balance between personalized content needs and overall system performance should be considered.
- Thorough testing[en] Make sure to conduct thorough content entry, frontend display, search filtering, and other tests in the test environment before using a custom model in production, to ensure that all functions operate normally.
By mastering the AnQiCMS content model customization features, you will be able to fully control the structure and display of the website content. No matter how special your business is, AnQiCMS can provide strong and flexible support to help you build a truly personalized website.
Common Questions (FAQ)
1. What impact will it have if I modify or delete a custom content model?
When modifying an existing model field, if it's only adjusting the field name or display order, it usually won't affect the existing data.If you change the 'Call field' or 'Field type', or delete a field, the existing content data associated with that field may be lost or may not display correctly.AnQiCMS will prompt you to delete the model, and all documents and categories under the model will also be deleted. Therefore, be cautious before performing such operations and make sure to backup your data.
2. Can I reference or use a custom field from another content model within a content model?
In AnQiCMS, the design of the content model is relatively independent.Each content model's custom field belongs only to itself.You cannot directly reference a custom field defined in another model within a model's content.archiveListLabels are queried and combined across models based on ID, category, and other conditions.
3. Will creating a large number of custom content models and fields affect website performance?
AnQiCMS is developed in Go language, with high performance and high concurrency features. Usually