How to define fields in the content model to achieve personalized display of different types of content?

Calendar 👁️ 77

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 asprice/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 witharchiveFiltersTag 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)

  1. 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.

  2. 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.

  3. 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.

Related articles

How to use the AnQiCMS backend settings to centrally manage and display the default thumbnail of the website?

In website operation, images play a vital role, especially when it comes to content lists or sharing, a suitable thumbnail can greatly enhance click-through rates and user experience.However, manually uploading thumbnails for each piece of content is time-consuming and prone to omissions, leading to broken images or a lack of visual consistency on the website page.AnQiCMS is well-versed in this field, providing powerful backend settings features, allowing you to easily achieve unified management and intelligent display of default thumbnails on your website. We will explore the convenient settings of the AnQiCMS backend step by step.

2025-11-08

When the custom URL does not work, how should I investigate the content display problem?

In website operation, a clear and easy-to-understand URL structure is crucial for search engine optimization (SEO) and user experience.AnQiCMS (AnQiCMS) offers powerful custom URL functionality, allowing you to flexibly configure links based on content models, categories, articles, etc.However, you may sometimes find that the custom URL set up in the background does not display as expected on the frontend page, or that clicking on it results in a 404 error.When encountering this situation, we can follow the following steps to troubleshoot, locate, and solve the problem step by step.

2025-11-08

How to ensure that each site's content can be displayed independently in multi-site management?

In today's increasingly complex digital operation, many companies or individuals often need to manage multiple websites, which may be show sites of different brands, or independent content platforms for different markets or business lines.In response to such needs, AnQiCMS's multi-site management feature provides an efficient and powerful solution, allowing users to unify the operation and maintenance of multiple websites in a single system.However, while enjoying the convenience of management, ensuring that each site's content can be displayed independently without interference is one of the most concerns for operators.

2025-11-08

How to solve the problem of page garbled display caused by incorrect encoding of AnQiCMS template files?

During the process of building a website with AnQiCMS, you may encounter situations where the page display appears garbled, which undoubtedly affects user experience and reduces the value of the carefully crafted page.Generally, such problems are caused by incorrect encoding settings in the template file.This article will detail how to troubleshoot and resolve the problem of garbled display caused by encoding issues in AnQiCMS template files, ensuring that your website content is clear and accurate.### Understanding the Root Cause of Garbled Characters Garbled characters, simply put, are the result of computers using the wrong encoding method to interpret data

2025-11-08

How can Anqi CMS protect original content display on the front end through anti-crawling interference codes and watermark functions?

## Protect Originality: How Anqi CMS Protects Your Front-end Content Through Anti-Crawling Interference Codes and Watermark Features In today's explosive growth of digital content, the value of original content is self-evident, but the problem of content theft and plagiarism that follows also causes countless creators a headache.When you put a lot of effort into writing articles or designing beautiful pictures, and they are picked up and published by others without any effort, the feeling of frustration is indescribable.AnQi CMS knows that originality is not easy, so it specially built strong anti-collection interference codes and picture watermarking functions, aiming to display on the front-end layer

2025-11-08

How to traverse and display nested categories or content structures in a template?

In website operation, we often need to build complex and layered content structures, such as multi-level classification navigation, product tree structures, or nested display of related articles under categories.AnQiCMS (AnQiCMS) with its flexible template engine and rich tag features makes it simple and efficient to traverse and display these nested structures in templates.The AnqiCMS template system uses syntax similar to Django, which means you will mainly output data through `{{variable}}` and execute logical control through `{% tags %}`

2025-11-08

How to display and manage exclusive content for different user groups or VIP users in AnQiCMS?

Today in the era of digital content operation, providing exclusive content for specific user groups has become a common and efficient strategy, whether it is for content monetization, enhancing user loyalty, or creating a unique community experience.AnQiCMS as a flexible enterprise-level content management system provides strong and easy-to-operate support in this regard.One of the core strengths of AnQiCMS is its comprehensive user group management and VIP system.

2025-11-08

How to quickly fill content through content collection and batch import functions, and ensure its normal display?

## Quickly fill in website content, Anqi CMS helps you display efficiently At the beginning of website operation or when a large amount of content needs to be updated, manually publishing content one by one is undoubtedly a time-consuming and labor-intensive task.The content collection and batch import function has emerged, aimed at helping us solve this pain point and making the filling of website content more efficient than ever before.AnQiCMS (AnQiCMS) is a powerful content management system that provides a mature and easy-to-use solution in this aspect, not only helps us quickly obtain content, but also ensures that these contents are presented normally and beautifully on the website.###

2025-11-08