In AnQi CMS, the content model is the core of website content management, which provides a structured way to organize and display different types of information.Flexibly using the custom field function in the content model can greatly enhance the personalized display capabilities of website content, meeting various unique business needs.
Core: Flexibility and custom fields of the content model
The AnQi CMS allows us to create or modify content models based on the actual operational needs of the website.This is not just simple articles and product categories, but also the key to customizing data structures for each type of content.For example, a common 'article' model might only need a title, content, and publish date, but a 'product' model might 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 with its own attributes.
How to define custom fields
The process of defining custom fields is intuitive and efficient.Enter the backend management interface of AnQi CMS, find the 'Content Model' option under 'Content Management'.Here, we can choose an existing model to edit or create a completely new model.
In the model editing interface, there is a key area called 'Content Model Custom Fields'.This is where we define the personalized content attributes.
- 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', and so on.
- Field call:This is the English identifier called in the database and template. It is recommended to use concise and meaningful letters, like
price/location/authorEmail. This name is the key called by the template. - Field Type:The AnQi CMS provides various field types to accommodate different types of data:
- Single-line text:Suitable for brief text input, such as titles, names, short links, etc.
- Numbers: Designed specifically for numeric data, such as prices, inventory quantities, ratings, etc.
- Multi-line text:Suitable for longer text content, 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 preset options that the user can only choose one from, such as 'product color', 'article difficulty level'.
- Multiple selection:Allow users to select multiple pre-set options, such as 'Applicable Platforms', 'Article Tags'.
- Dropdown selection:Similar to single selection, but presented in a dropdown menu form, saving page space.
- Mandatory:According to business logic setting, if this field is crucial for the integrity of the content, then check this item.
- Default value:Set an initial value for the field. For selection fields, the list defined here will be the options available, with each option 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 selection: apartment, villa, shop) and other custom fields.
Fill in custom fields in the content.
Once these custom fields are defined in the content model, they will appear in the "Other Parameters" section of the content editing page when we create or edit content belonging to that model in the "Content Management" section on the backend.Content editors only need to follow the prompts and 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 on the frontend page as personalized content display.The Anqi CMS provides powerful template tags, which can be easily called on the website front-end to access these custom data.
- Directly call a single field:If we know the name of the 'Called Field' of the custom field, we can use it directly.
{% archiveDetail with name="调用字段名" %}Or, inforIn the loopitem.调用字段名to get its value. For example, to display the product price, you can directly use{% archiveDetail with name="price" %}. - Translate all custom fields:For scenarios where it is necessary to display all custom parameters uniformly,
{% archiveParams params %}Tags. It returns a list of all custom fields that we can use in the template.{% for item in params %}Loop to 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|safeFilter to ensure 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 according to conditions such as 'Property type', 'Price range', etc.
By these flexible field definitions and template invocation methods, we can create rich and diverse display interfaces for different types of content.For example, a 'press release' model can have 'issuer', 'contact' fields; a 'movie' model can have 'director', 'main cast', 'release date' fields.These additional fields make each piece of information more in-depth and practical.
In summary, the content model custom field feature of Anqi CMS provides website operators with a great degree of freedom.It not only makes the background content management more standardized and efficient, but more importantly, it allows the front-end content presentation to be highly customizable according to specific needs, thereby providing users with more precise and personalized information services.
Common Questions and Answers (FAQ)
Q: Will the published content be affected if I modify the custom field type of the content model?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 and test its impact on existing content before modifying the field type.If there is a significant type difference, 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, Aik CMS allows them to be configured as filter parameters. Combined
{% archiveFilters %}And template tags, we can build filters based on these custom fields on the front-end, allowing users to find the desired content 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 judge whether a custom field has a value in the template. For a single field, you can directly use
{% if 字段名 %}to make the judgment. 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 for loop iteration, it can beforjudged within the loop:item.ValueJudgment:{% for item in params %}{% if item.Value %}<div>{{ item.Name }}:{{ item.Value }}</div>{% endif %}{% endfor %}This method ensures that custom fields are displayed only when they contain actual content, preventing blank tags or incomplete information from appearing on the page.