How to customize the content model to meet various content display needs?

In the field of content management, website operators often face a variety of content display needs.From traditional article publishing and news updates, to complex e-commerce product details and event registration pages, 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.The auto CMS understands this diversity and therefore provides highly flexible content model customization features, aiming to help users easily manage various types of content and create exclusive and efficient content display systems.

Content model: The foundation for building diverse content

In the AnQi CMS, the content model can be understood as the 'blueprint' or 'skeleton' of the content.It defines which data fields and attributes a certain type of content should include.For example, an “article” model may contain title, author, publish date, content, etc. fields; while a “product” model may require product name, price, inventory, image set, detailed description, etc.The 'Article Model' and 'Product Model' are provided by the AnQi CMS system by default, as the basic content types most commonly used.

But the content requirements in reality are far more than that.Imagine if your website needs to showcase a series of complex electronic products, each with unique parameters such as processor model, memory size, and screen size; or if you are running an event publishing platform, where you need to add start time, end time, location, and registration links for each event.If only simple fixed models are used, it is difficult to manage these specific information structurally, let alone display and retrieve them efficiently.This is when custom content models become particularly crucial, as they can greatly enhance the adaptability of the system and meet various personalized content publishing needs.

How to customize the content model

When creating or modifying content models, several core elements need to be defined:

  1. Model nameThis is the Chinese display name of the model on the backend and frontend, which is convenient for identification and management. For example, 'Activity Details', 'Talent Recruitment'.
  2. Model table name:This is the table name stored in the database for the model data, it must be used to ensure the normal operation of the system and data storagein English lowercase letters.
  3. URL alias:Used to generate friendly URL paths, it is also recommended to usein English lowercase lettersFor example, in the use of pseudo-static rules{module}the alias will come in handy when called.
  4. Title name:Define the prompt text for the title field when publishing content, for example, in the product model, you can set it to "Product Name"。

In addition to these basic settings, the most powerful aspect of the content model is itsCustom fieldsFunction.By adding custom fields, you can inject personalized data structures for different types of content.

  • Single Line Text: Suitable for brief text information, such as article authors, product brands, event locations, etc.
  • NumberEnglish: Designed specifically for numerical data, such as product prices, inventory quantities, property areas, etc., to ensure the accuracy of data formats.
  • Multi-line text:Applicable to longer descriptive content, such as product descriptions, event agendas, personal introductions, etc.
  • Single selection:Provide preset options, users can only select one item from them, such as product color, service type, free shipping or not, etc.
  • Multiple selectionSimilar to single selection, but allows users to select multiple preset options, such as product sizes (S, M, L, XL) and so on.
  • Drop-down selectionThe following drop-down menu provides preset options for users to select from, commonly used for regions, industry classifications, etc.

When defining these custom fields, you can also set whether they areMandatory itemand provides fields of single selection, multiple selection, and dropdown selection typesDefault valueEnsure the completeness and standardization of the content. For example, set options such as 'Red, Blue, Black' for the 'Product Color' field, so the publisher can simply check the box.

Display custom content on the front end

Customize the content model and add rich fields, and the next step is to present these data on the front-end pages of the website.The template engine of Anqi CMS provides intuitive and flexible tags, allowing you to easily call and display these custom data in templates.

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

  2. Loop to display all custom fields: Sometimes, you may want to display all custom fields of a certain content in a list format, especially when there are many product parameters or event information.archiveParamsLabels are born for this. It will return an array of custom fields, which you can iterate over to display each field's 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: Besides 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 time, you can usecategoryDetailorpageDetailTag these fields for easy access. For example, to 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 listFurther more, custom content model data can also be used to build complex content lists