In AnQi CMS, configuring unique display fields for different content models is a crucial function to meet the diverse display needs of website content.This capability allows us to flexibly customize the structure of articles, products, activities, or any other type of content based on specific business requirements, thereby providing a highly personalized content display experience.
Understand the content model: the foundation of personalized display
One of the core strengths of AnQiCMS is its 'flexible content model'.It allows us to break through the fixed limitations of traditional content management systems such as "articles" or "pages", and customize content types according to actual business scenarios.Imagine that your website not only needs to publish ordinary news articles, but also needs to display complex product details, activity registration pages, and even professional industry reports.Each content type has its unique properties, such as products need to have price, inventory, SKU;The event must have a start time, end time, and a maximum number of registrants;While news articles may require author, source, and other information.
The content model is a structured tool provided by AnQiCMS, which defines all the fields contained in a certain type of content.The system is pre-installed with the "Article Model" and "Product Model", but the real power lies in being able to create new models as needed, or modify existing models to equip them with unique field sets.
Configure unique display fields: the key to custom content models
The first step in displaying personalized content is to deeply customize your content model, adding exclusive display fields for it.
First, you need to enter the AnQiCMS management background, find "Content Management" in the left navigation menu, and then click "Content Model".This will list all existing content models, you can choose to edit an existing model, or click 'Add a custom model' to create a new content type.
Whether it is editing or adding, the core lies in the "Content Model Custom Field" area of the model detail page.Here, you can define any number of exclusive fields for the current model.Each custom field's settings are very intuitive:
- Parameter NameThis is the Chinese display name of the field, convenient for you to identify when publishing content in the background, such as 'Product Price', 'Event Location', etc.
- Field invocationThis is the unique identifier of the field, used for template calls and database storage. Please make sure to use letters, for example
productPrice/eventLocationThis name must be unique and consistent throughout the system. - Field type: AnQiCMS provides various field types to meet different data format requirements:
- Single-line text: Suitable for short text input, such as titles, contact names.
- NumberEnsure the content is purely numeric, such as prices and quantities.
- Multi-line textSuitable for long text descriptions, such as product introductions and event details.
- Single choice: Provide preset options, the user can only select one item, such as "gender", "product color".
- Multiple selectionsProvide preset options, the user can select multiple options, such as "Product Feature Tags".
- Drop-down selectionSimilar to single choice, but presented in the form of a drop-down menu.When selecting a single, multiple, or dropdown option, you also need to enter each option on a new line in the "default value", and the system will automatically parse it into a list of selectable options.
- Mandatory?You can decide whether the field is required to be filled in when publishing content based on the importance of the content.
- Default valueSet a default value for the field. This is where you define the option list for select fields.
After completing the field configuration, save the model. When you enter the "Content Management" "Publish Document" page, select the category associated with your customized model, and you will find that these newly defined fields are clearly presented in the "Other Parameters" section, waiting for you to fill in specific data for each piece of content.
Display custom fields in the frontend template: transform data into visual elements.
It is not enough to configure fields and data in the background to achieve personalized display; the key is how to extract and present these custom field data in the website's front-end template.AnQiCMS's template engine supports Django-like syntax, making data calls very flexible and powerful.
How many common methods are there to display custom fields in a template:
Directly call a specific custom field If you know the name of the "callback field" of the custom field, you can use it directly.
archiveDetailLabel to retrieve and display its value. For example, if your product model has a custom field namedproductPriceYou can call it like this in the product detail page template:<div>产品价格:{% archiveDetail with name="productPrice" %}</div>For custom fields of multi-image upload type, for example
arcimagesyou may need to display in a loop:{% archiveDetail arcimages with name="arcimages" %} <ul class="product-gallery"> {% for img in arcimages %} <li><img src="{{img}}" alt="产品图片" /></li> {% endfor %} </ul>Loop through all custom fieldsIn some cases, you may want to dynamically list all custom fields and their values without needing to know their names. At this point,
archiveParamsTags are very useful. It will return an array containing all custom fields, you can iterate through the array to display:{% archiveParams params %} <div class="product-specs"> {% for item in params %} <div> <span>{{item.Name}}:</span> <!-- 显示字段的中文名称 --> <span>{{item.Value}}</span> <!-- 显示字段的值 --> </div> {% endfor %} </div>If you want to exclude some custom fields that are not needed for frontend display, you can add conditional judgments in the loop, for example:
{% archiveParams params %} <div class="product-specs"> {% for item in params %} {% if item.Name != '内部备注' and item.Name != '管理代码' %} <div> <span>{{item.Name}}:</span> <span>{{item.Value}}</span> </div> {% endif %} {% endfor %} </div>Combine the filtering function to achieve advanced display: In addition to being displayed on the detail page, you can also use custom fields to implement complex filtering functions on the list page. AnQiCMS's
archiveFiltersTags allow you to create dynamic filter conditions based on custom fields defined in the model.For example, on a real estate information website, you can use custom fields such as 'house type', 'area', 'price range', etc. to help users locate the listings they are interested in.After the user selects the filter condition,archiveListTags will automatically search based on these conditions and display matching content, greatly enhancing the interactivity and user experience of the website.
**Practice and Precautions
- Naming conventionSelect a concise and meaningful English name for the 'invoked field', which is convenient for template developers to understand and call.
- Field type matchAccording to the actual data content, choose the most suitable field type, for example, selecting the 'number' type for price can avoid input errors and facilitate subsequent numerical calculations.
- Plan firstBefore creating a content model and custom fields, it is best to plan all the content properties you want to display to avoid frequent modifications later.
- Test verification:After completing the configuration and call of custom fields and templates, be sure to carry out comprehensive testing on different pages and scenarios to ensure that the content is displayed correctly and beautifully.
- Focus on SEOAlthough custom fields are mainly used for content display, their content itself will also be crawled by search engines.Ensure that the text content in the custom field is valuable and helps improve page relevance.
By using AnQiCMS's flexible content model and custom field features, you can easily achieve highly personalized content management and display.Whether it is to build a functional e-commerce platform or operate a content-rich media website, these tools will help you a lot, making your website content more attractive and more in line with user needs.
Frequently Asked Questions (FAQ)
**1. Why am I unable to publish an article after adding custom fields in the content model?