How to customize the content model to meet the needs of diverse content display?

In the field of content management, website operators often face a variety of content display needs.From traditional article publishing, news updates, to complex e-commerce product details, event registration pages, and even team member introductions or customer case displays, each type of content has its unique structure and field requirements.If relying solely on a single content format, it is not only difficult to manage efficiently, but it will also limit the flexibility and user experience of the website.AnQi CMS understands this diversity and therefore provides a highly flexible content model customization feature, aimed at helping users easily manage various types of content and build a dedicated and efficient content display system.

Content model: The foundation for building diversified content

In AnQi CMS, the content model can be understood as the 'blueprint' or 'skeleton' of the content.It defines what data fields and properties a certain type of content should include.For example, an "article" model may contain fields such as title, author, publication date, content, and so on;And a "product" model may require product name, price, inventory, image set, detailed description, and so on.The Anqi CMS system provides the 'Article Model' and 'Product Model' by default, as the most commonly used content type basis.

But the content requirements in reality are not limited to this. Imagine that if your website needs to display a series of complex electronic products, each product has its own parameters such as processor model, memory size, screen size, and so on;Or you are running an event publishing platform, and you need to add start time, end time, location, and registration link information for each event.If only simple fixed models are used, it is difficult to manage these specific information structurally, let alone display and retrieve it efficiently.At this point, a customized content model is particularly crucial, as it allows the system to greatly enhance its adaptability and meet various personalized content publishing needs.

How to customize the content model

The process of customizing the content model of AnQi CMS is intuitive and powerful.You can find the "Content Model" feature under the "Content Management" menu in the background.Here, you can choose to modify an existing model, such as adding more dedicated fields to the 'Product Model', or you can create a completely new custom model to meet your unique business needs.

When creating or modifying a content model, there are several core elements that need to be defined:

  1. Model name: This is the Chinese display name of the model on the back-end and front-end, convenient for identification and management. For example, 'Event Details', 'Talent Recruitment'.
  2. Model table nameThis is the table name stored in the database for model data, it must beEnglish lowercase letters.
  3. URL aliasThis is used to generate friendly URL paths, it is also recommended to useEnglish lowercase lettersFor example, it is used in pseudo-static rules.{module}When called, this alias will come into play.
  4. Title Name: Define the prompt text for the title field when publishing content, for example, in a product model, you can set it to "Product Name".

In addition to these basic settings, the most powerful feature of the content model is itsCustom fieldFunction. By adding custom fields, you can inject personalized data structures for different types of content.The Anqi CMS supports various field types and can cover the vast majority of content management needs:

  • Single-line text: Suitable for short text information, such as article authors, product brands, event locations, and so on.
  • Number: Designed specifically for numerical data, such as product prices, inventory quantities, property areas, etc., to ensure the accuracy of data formats.
  • Multi-line text: Suitable for long descriptive content, such as product details, event agenda, personal introduction, etc.
  • Single choice: Provide preset options, the user can only select one, such as product color, service type, free shipping, etc.
  • Multiple selections: Similar to a single selection, but allows users to choose multiple preset options, such as product sizes (S, M, L, XL), etc.
  • Drop-down selection: Provide preset options in the form of a dropdown menu, from which the user can select an item, commonly used for regions, industry classifications, etc.

When defining these custom fields, you can also set whether they arerequiredProvide for single-choice, multiple-choice, and dropdown field typesDefault valueEnsure the completeness and standardization of the content. For example, set options such as 'red, blue, black' for the 'product color' field, and the publisher can simply check the box.

Display custom content on the front end

After customizing the content model and adding rich fields, the next step is to present these data on the website's frontend page.The AnQi CMS template engine provides intuitive and flexible tags, allowing you to easily call and display these custom data in templates.

  1. Display custom fields on the detail pageWhen you need to display the details of a single content (such as an article or a product page), you can usearchiveDetailLabel directly calls a custom field. For example, if you add a single-line text field namedauthorto the article model, you can call it like this in the article detail template:<div>作者:{% archiveDetail with name="author" %}</div>Or if you have customized a field namedproduct_specsto record product specifications in multi-line text, it can be displayed as follows:<div>产品规格:{% archiveDetail with name="product_specs" %}</div>For rich text custom fields containing HTML, such as 'Product Description', in order to ensure that the content is parsed and displayed correctly, you need to use|safeFilter, and if the content is written in Markdown, it can also be added withrender=trueparameters to render into HTML:<div>{% archiveDetail productContent with name="product_long_description" render=true %}{{productContent|safe}}</div>

  2. Loop to display all custom fieldsSometimes, you may want to display all custom fields of a certain content in a list, especially when there are many product parameters or event information.archiveParamsTags are born for this. It will return an array of custom fields, which you can iterate through to display each field name and value:

    {% archiveParams params %}
    <div>
        {% for item in params %}
        <div>
            <span>{{item.Name}}:</span>
            <span>{{item.Value}}</span>
        </div>
        {% endfor %}
    </div>
    {% endarchiveParams %}
    
  3. Custom fields for categories or single pages: In addition to the content detail page, you may also add custom fields for categories or single pages, such as adding a "Category Banner Image" field for the "Product Category". At this point, you can usecategoryDetailorpageDetailLabel to call these fields. For example, get the custom Banner image for categories:<div><img src="{% categoryDetail with name="category_banner_image" %}" alt="分类Banner" /></div>

  4. Filter and display in the content list.Further, the data of the customized content model can be used to build complex content lists