In Anqi CMS, the content model is the core of website content management, providing a structured way to organize and display different types of information.Effectively utilizing the custom field function in the content model can greatly enhance the personalized display capabilities of website content, meeting various unique business needs.
Core: The flexibility of the content model and custom fields
The AnQi CMS allows us to create or modify content models based on the actual operational needs of the website.This is not just a simple article and product classification, but also the key to customizing data structures for each type of content.For example, a common "article" model may only need a title, content, and publication date, but a "product" model may require information such as price, inventory, and SKU.By custom fields, we can integrate this specific information into the content model, making each piece of content unique.
How to define custom fields
The process of defining custom fields is intuitive and efficient. Enter the AnQi CMS backend management interface, find the 'Content Management' option under 'Content Model'.Here, we can choose an existing model to edit or create a new one.
In the model editing interface, there is a key area called "Custom fields of content model".This is where we define personalized content attributes. We can click to add fields, and set the following important properties for the new field:
- Parameter name:This is the Chinese name displayed in the background management interface, which is convenient for content editors to understand and fill in, such as "Product Price", "Event Location", "Author Email", etc.
- Call field:This is the English identifier used in the database and template. It is recommended to use concise, meaningful letters, such as
price/location/authorEmail. This name is the key to the template call. - Field type:The AnQi CMS provides various field types to adapt to different types of data:
- Single-line text:Suitable for brief text input, such as titles, names, short links, etc.
- Number: Designed for numerical data, such as prices, inventory quantities, ratings, etc.
- Multi-line text:Content suitable for long text, such as product descriptions, event details, etc. It even supports Markdown rendering, making it convenient for writing and displaying rich text.
- Single choice:Provide a set of predefined options that the user can only select one from, such as 'product color', 'article difficulty level'.
- Multiple selection:Allow users to select multiple pre-set options, such as "Applicable Platform", "Article Tags".
- Dropdown selection:Similar to single selection, but presented in a dropdown menu to save page space.
- Mandatory?:According to business logic setting, if this field is crucial for content integrity, check this item.
- Default:Set an initial value for the field. For selection fields, this will define the list of options available, each on a new line.
For example, if we are creating a “Real Estate Information” model, we may need to defineaddress(Single-line text),bedrooms(Number),price(Number),property_type(Dropdown options: apartment, villa, shop) and other custom fields.
Fill in the custom field in the content
Once these custom fields are defined in the content model, when we create or edit content belonging to the model under the "Content Management" backend, these fields will appear in the "Other Parameters" section of the content editing page.Content editors only need to follow the prompts to fill in the corresponding personalized information for each specific article, product, or event.
Implement personalized display in the template
The value of the custom field ultimately manifests in the personalized display of content on the front-end page.AnQi CMS provides powerful template tags that can easily be called on the website front end to access these custom data.
- Directly call a single field:If we know the name of the custom field's 'call field', we can use it directly
{% archiveDetail with name="调用字段名" %}orforin the loopitem.调用字段名To get its value. For example, to display the product price, you can use it directly{% archiveDetail with name="price" %}. - Loop through all custom fields:For scenarios where you need to display all custom parameters uniformly, you can use
{% archiveParams params %}Label. It will return a list containing all custom fields that we can use in the template{% for item in params %}To loop and display each field's 'parameter name' and 'parameter value'. This is very useful when displaying product specifications or technical parameters. - Rich text field rendering:If the custom field is multiline text and contains Markdown or other HTML content, we should use
|render|safeThe filter ensures that content is displayed in the correct format on the front end, for example{{ item.Value|render|safe }}.renderConverts Markdown to HTML,safeIt avoids the escaping of HTML content, allowing it to be normally parsed by the browser. - Used for filtering and searching:Custom fields can also be used with
archiveFiltersTag combination, create filters based on these fields, allowing users to search content based on conditions such as 'property type', 'price range', etc.
By these flexible field definition and template calling methods, we can create a rich and diverse display interface for different types of content.For example, a "press release" model can have fields such as "publisher", "contact";A "movie" model can have "director", "main cast", and "release date" fields.These additional fields make each piece of information more profound and practical.
In summary, the content model custom field function of Anqi CMS provides website operators with great freedom.It not only makes the background content management more standardized and efficient, but more importantly, it allows the front-end content display to be highly customized according to specific needs, thereby providing users with more accurate and personalized information services.
Frequently Asked Questions (FAQ)
Q: If I change the custom field type of the content model, will the published content be affected?A: Changing the type of a custom field (for example, from 'Number' to 'Single Line Text') may affect the display and data processing of published content.The system will try to be compatible in the background, but to avoid potential data confusion or display errors, it is recommended to back up the data before modifying the field type and test its impact on the existing content.If the type difference is significant, manual adjustment of the affected content may be required.
Q: Can custom fields be used for website search and filtering?A: Yes, custom fields can be used for website search and filtering. After defining fields in the content model, Anqi CMS allows them to be configured as filter parameters. Combine
{% archiveFilters %}We can build filters based on these custom fields on the front end, allowing users to find the content they need more accurately.Q: How to determine if a custom field has a value in a template before displaying it?A: It is very simple to determine if a custom field has a value in the template. For a single field, you can use it directly
{% if 字段名 %}to determine. For example, if the product model has a custom fieldstock(Stock), it can be written like this in the template:{% archiveDetail stock_value with name="stock" %}{% if stock_value %}<p>库存:{{ stock_value }}</p>{% endif %}For the custom field list traversed by the loop, it can be:forJudged within the loop:item.ValueJudgment:{% for item in params %}{% if item.Value %}<div>{{ item.Name }}:{{ item.Value }}</div>{% endif %}{% endfor %}This way ensures that only when the custom field has actual content will it be displayed, avoiding blank tags or incomplete information on the page.