How to display the custom parameters of the product on the product detail page (for example: color, size)?

Calendar 👁️ 86

In website operation, adding customized parameters to the product detail page, such as color, size, etc., is an important aspect to improve user experience and provide more detailed product information.AnQiCMS (AnQiCMS) takes advantage of its flexible content model and powerful template system to easily meet this requirement.Next, we will delve into how to display these custom parameters on the product detail page.


The first step: define custom fields in the product content model on the backend

One of the core strengths of AnQi CMS is its highly flexible content model. To display custom parameters on the product detail page, we first need to add corresponding fields to the product model.

You can access the content model management interface through the following path:内容管理-u003e内容模型. The system has built-in 'Article Model' and 'Product Model'.Generally, custom parameters of the product detail page are added to the "product model".You can choose to edit an existing "product model" or create a new one as needed.

After entering the product model editing page, you will see a section named "Content model custom fields".This is where we define the unique properties of the product. Click the "Add Field" button to add new entries for your product parameters:

  • Parameter name:These are the field names you will see in the backend management, such as 'Color', 'Size', 'Material', etc.
  • Call field:This is the unique identifier used when calling this parameter in the front-end template, it is usually recommended to use lowercase English letters, such as "color", "size", "material".This field name is crucial, please ensure its uniqueness and ease of memory.
  • Field type:Choose the appropriate field type based on the nature of the parameter.
    • “Color” parameters are usually pre-set options that can be selected as either “Single selection” or “Dropdown selection”, and then enter each option in the “Default value” field, such as: Red, Blue, Black.
    • The "size" option can be selected as a fixed option (such as S, M, L) and can also be selected as a single choice or drop-down selection; if it is a user-defined input (such as 100x200cm), then select a single-line text.
    • For more complex descriptive parameters, you can choose 'Multi-line text'.
  • Mandatory?:Determine whether the parameter is required based on your business requirements.
  • Default:Set a default value for the field, especially when using "single selection", "multiple selection" or "drop-down selection", here to define all available options.

After defining the field, don't forget to click the 'Save' button at the bottom of the page to ensure your changes take effect.

Step 2: Fill in the custom parameter data for the specific product.

After you define custom fields in the product model, these fields will automatically appear on the publish or edit page of the corresponding content model.

Go to内容管理-u003e文档管理Select the product you want to edit, or click 'Add New Document' to create a new product.In the product editing page, please ensure that the 'category' you select is associated with the 'product model' you are modifying.

At the bottom of the page, you will find a collapsible area named "Other Parameters".Expand this area, and you will find all the custom parameter fields defined just now.Here, you can fill in specific information such as 'color' and 'size' for the current product.For example, if your product is a red L-sized T-shirt, you can select or enter the corresponding value here.

After completing, save the product information. This custom data will be associated with your product content.

Step 3: Display custom parameters in the front-end template.

After the data is ready, the final step is to modify the product detail page template, and display these custom parameters to your visitors.The Anqi CMS uses the Django template engine syntax, which is very intuitive.

usually, the template file of the product detail page will be/template/您的模板目录/product/detail.html. You can edit it online through the 'template design' feature in the background, or directly modify the file on the server.

Inproduct/detail.htmlIn the template, you can use two main ways to retrieve and display custom parameters:

  1. Directly call the known custom fields:If you know the name of the 'call field' for the custom parameter (for example, the one we set in the first step), and you only want to display specific parameters, you can directly use them in the templatecolorandsize){{archive.你的调用字段名}}Call it in the form of.

    <div>
        产品颜色:{{archive.color}}
    </div>
    <div>
        产品尺寸:{{archive.size}}
    </div>
    

    Or use a more general one.archiveDetailTags:

    <div>
        产品颜色:{% archiveDetail with name="color" %}
    </div>
    <div>
        产品尺寸:{% archiveDetail with name="size" %}
    </div>
    
  2. Loop through all custom parameters.This approach offers more flexibility, especially suitable for products with a variable number of custom parameters, or when you want to display all parameters in a list format. You can usearchiveParamsLabel to get all custom parameters and throughforloop through it.

    <div class="product-attributes">
        <h3>产品参数</h3>
        {% archiveParams params %}
        {% for item in params %}
        <div class="attribute-item">
            <span class="attribute-name">{{item.Name}}:</span>
            <span class="attribute-value">{{item.Value}}</span>
        </div>
        {% endfor %}
        {% endarchiveParams %}
    </div>
    

    This code will iterate through all the filled custom parameters in the product model and display them one by one in the form of 'Parameter name: Parameter value'.item.NameThe parameter name set on the back-end,item.ValueThe specific parameter value you entered for the product.archiveParamsThe label will return the parameters in the form of an ordered list, so it can be used directly.forLoop.

After modifying the template, save the file. At this point, when you visit your product detail page, you will see that the product colors, sizes, and other custom parameters are clearly displayed.

By following these three simple steps, you can fully utilize the flexible content model of Anqi CMS, add rich and personalized custom parameters to your product detail page, and greatly enhance the professionalism and user experience of the website content.


Frequently Asked Questions (FAQ)

  1. Why did I set custom parameters but the product details page did not display?This could be due to several reasons: First, please check if you have correctly defined the field in the "content model", especially whether the "calling field" matches the name used in the template.Secondly, confirm that you have filled in the corresponding data for the product in the "Other Parameters" area when publishing or editing the product.Finally, if it does not display after modification, try clearing the browser cache or the system cache on the CMS backend.

  2. How should I operate if I want different types of products to display different custom parameters?The 'Content Model' design of AnQi CMS is designed to solve this problem.You can create multiple "product models", such as "clothing product model", "electronic product model", etc., each model defining a set of different custom parameters.Then, when creating a product, select the category under the corresponding content model for the product, so products of different models will display their unique parameters.

  3. Can the display order of custom parameters be adjusted?When you use{% archiveParams params %}Label and pass throughforWhen iterating over the display, the order of the parameters is usually determined by the order in which you add these custom fields in the content model.If you need to adjust the display position of a parameter, you can delete the field on the content model editing page, then re-add it in a new order, or if the CMS provides the feature of field drag-and-drop sorting, you can adjust it directly by dragging.

Related articles

How to correctly render Markdown-formatted article content as HTML and display mathematical formulas in AnQiCMS?

In AnQi Content Management System (AnQiCMS), we are committed to making content creation and display more flexible and efficient.For users accustomed to writing articles in Markdown format, we provide powerful support, ensuring that Markdown content is correctly rendered into HTML, and can easily handle complex mathematical formulas and flowcharts, bringing vitality to technical documents, tutorial articles, and other content.### Enable Markdown Editor: The First Step of Content Creation Enjoy Markdown Convenience in AnQiCMS

2025-11-09

How to implement conditional judgment in a template, for example, whether to display an image based on whether the article has a thumbnail?

In website content presentation, images play a crucial role.However, not all content has corresponding thumbnails, or for design aesthetics and loading speed considerations, we may need to decide based on the actual situation whether to display images, or even display different placeholders.AnqiCMS provides a flexible and powerful template engine, allowing us to easily implement this conditional image display logic, thereby enhancing the flexibility and user experience of website content.This article will focus on how to decide whether to display an image in the AnqiCMS template based on whether the article has a thumbnail

2025-11-09

How to control the number of characters displayed for the article abstract (Description) in the list and automatically add an ellipsis in AnQiCMS?

When operating website content, the display length of the article summary (Description) on the list page is crucial for the neatness of the page and the user experience.A long summary can make the page look bloated and difficult to browse quickly, while a short one may not attract readers to click.AnQiCMS as a feature-rich content management system, provides flexible template tags and filters, allowing us to easily implement precise control over the word count displayed in article summaries and automatically add elegant ellipses.###

2025-11-09

How to set up a dynamic carousel effect for the Banner image on the homepage of AnQiCMS website?

In AnQiCMS, setting a dynamic banner slideshow on the homepage can effectively enhance the visual appeal of the website and convey key information.AnQiCMS provides flexible and intuitive features to help us achieve this goal.Next, we will step by step understand how to set up from the background to the front-end template editing, creating an animated carousel effect for the homepage.### 1. Backend configuration of Banner image: Content and grouping Firstly, we need to prepare the images and relevant information for the carousel in the AnQiCMS backend

2025-11-09

What thumbnail processing methods does AnQiCMS support to optimize the effect of images in different display scenarios?

In modern website operations, images are not only an important part of the content, but also a key factor affecting user experience and website performance.A well-managed image system can significantly improve the loading speed, visual appeal, and search engine optimization effect of a website.AnQiCMS understands the importance of image optimization and therefore provides users with a variety of flexible thumbnail processing methods to ensure that images achieve the desired effect in various display scenarios.AnQiCMS provides three core strategies for handling image thumbnails, each suitable for different display needs

2025-11-09

How can you implement a multi-dimensional filtering function on the article list or product list page (such as by price, attributes)?

I am glad to discuss with you how AnQi CMS can help us achieve multi-dimensional content filtering.In this era of information explosion, users are increasingly pursuing efficiency and personalization in obtaining content.A website that allows users to quickly locate content according to their own needs will undoubtedly greatly improve the user experience and conversion rate.AnQi CMS provides very powerful and flexible functions in this aspect, especially through custom content models and specific template tags, we can easily build multi-dimensional filtering functions on article list or product list pages, just like the "price filtering" commonly seen on e-commerce websites

2025-11-09

How to set up multilingual support in AnQiCMS and provide language switching options on the front-end page?

Today, with the deepening of globalization, multilingual support for websites is no longer an option, but a key factor for enterprises to expand into international markets and enhance user experience.AnQiCMS has fully considered this need, providing users with a flexible and powerful multilingual solution to ensure that your content can reach users all over the world and provide a friendly browsing experience in different cultural contexts.The core strategy of AnQiCMS in implementing multi-language functionality is to treat each language as an independent "site" for management, and to combine it with the translation mechanism at the template level

2025-11-09

How to precisely control the display level and sorting order of the navigation menu in AnQiCMS template?

In website operation, a clear and intuitive navigation menu is like a guidepost for visitors to explore the website.A well-designed navigation not only improves user experience but also helps search engines better understand the website structure.AnQiCMS provides a flexible mechanism to help users accurately configure the hierarchy and sorting of navigation menus in the background and implement these controls in the front-end templates. ### Build Navigation Skeleton: Backend Settings Are Key Navigation menu control in AnQiCMS starts from its backend management interface.This is like the blueprint design center of the navigation menu

2025-11-09