How can you clearly display the user's comment content, username, reply object, and posting time in the comment list?

Calendar 👁️ 63

In website content operation, the comment section is undoubtedly an important manifestation of user interaction and content depth.A well-designed, clear information presentation comment list that can not only significantly improve the user's browsing experience, but also effectively stimulate the vitality of the community.AnQiCMS's powerful template system provides us with flexible tools, allowing us to easily achieve the organization of comment content, commenters, reply objects, and posting time.

Understanding the core elements of the comment list

To build a visually appealing and practical comment list, we need to ensure that the following core information can be conveyed to each visitor in a straightforward and accurate manner:

  • Comment content:This is the most direct reflection of a user's thoughts and opinions, which is the core of the comment section.
  • Username:Identify the identity of the commenter, build an interactive atmosphere.
  • Reply to object:When a comment is a response to another comment, clearly indicating 'who the reply is to' helps users understand the context of the conversation.
  • Published time:Display the time when comments were posted, allowing users to understand the timeliness of the information and the sequence of comments.

The template tag system of AnQiCMS, especiallycommentListTags, which can help us accurately obtain and organize these comment data.

UtilizecommentListTag to get comment data

commentListThe tag is the core to get comment data. It returns a collection of comment objects, which we can iterate over to display each comment one by one.For example, to get all comments of the current article and perform pagination, you can use it like this:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {# 评论列表的展示逻辑将在这里展开 #}
{% endcommentList %}

In this code block,archive.Id Usually used to specify the unique identifier of the current page article, ensuring that the comments obtained are targeted at this article.type="page"Direct the system to provide pagination data for us, andlimit="10"then sets the display of 10 comments per page.commentsis the variable name we define for the obtained comment array.

Analyze the key information of the comment object

IncommentListIn the loop of tags, each iteration containsitemEach variable represents an independent comment data. ThisitemThe object carries all the information we need:

  • Comment content (item.Content):This directly corresponds to the user's input text. To ensure the correct rendering and safety of the content, if the comment content may contain HTML tags or Markdown format, we usually cooperate withsafeOr filter.renderfilter usage.
  • Username (item.UserName):Directly display the nickname or identifier of the commenter.
  • Publish time (item.CreatedTime):This is a Unix timestamp. To present the date and time in a user-friendly format, we need to usestampToDateFormat labels.
  • Reply object (item.Parent):This is a clever design of the AnQiCMS comment system. If the current comment is a reply to another comment, thenitem.ParentIt will be an object that contains the complete information of the replied comment. By simply checkingitem.ParentWhether it exists, we can judge whether this comment is a reply and further obtain the username of the replied comment (item.Parent.UserName) and content (item.Parent.Content).

Build a clear comment display structure: practical example

Now, let's combine this information to create a comment display template that is both intuitive and has a good user experience. Here is a practical example that considers the different display needs of ordinary comments and reply comments, and includes review status judgment and content truncation processing:

`twig

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {% for item in comments %}
        <div class="comment-item">
            <div class="comment-meta">
                <span class="user-name">
                    {# 根据评论状态显示用户名,如果未审核则提示 #}
                    {% if item.Status != 1 %}
                        <span class="status-pending">审核中:</span>{{item.UserName|truncatechars:6}}
                    {% else %}
                        {{item.UserName}}
                    {% endif %}
                </span>

                {# 如果是回复评论,

Related articles

How to use the `archiveFilters` tag to build a dynamic document filtering feature, such as filtering by product parameters?

Using AnQiCMS's `archiveFilters` tag to build an efficient and practical dynamic filtering function In the field of content management and e-commerce, users being able to quickly and accurately find the information they need is crucial for improving website experience and conversion rates.Imagine, when users browse products or documents on your website, if they can quickly filter out the content they want based on various conditions such as color, size, brand, and even more specific parameters like processor type, memory size, etc., this will greatly enhance their user experience.Provided by AnQiCMS

2025-11-08

How to customize and display a friendly shutdown notice when the website is in a closed state?

In website operation, we sometimes need to temporarily close the website, whether it is for system upgrades, data maintenance, or short-term business adjustments.It is crucial to display a friendly shutdown prompt to visitors in this case.This not only informs users of the website status, avoids unnecessary confusion, but also maintains the brand image and provides clear guidance for search engines.AnQiCMS (AnQiCMS) provides us with a flexible way to customize and display this information.### Enable website shutdown status and set basic prompts First, you need to set the website to shutdown status

2025-11-08

How to perform arithmetic operations such as addition, subtraction, multiplication, and division in the template and display the result?

In AnQiCMS template design, sometimes we need to perform arithmetic operations such as addition, subtraction, multiplication, and division on the numbers displayed on the page to present data more flexibly.Whether it is to calculate the total price of goods, display dynamic percentages, or perform simple processing of certain statistical data, AnQiCMS's template engine provides intuitive and powerful arithmetic calculation capabilities.AnQiCMS's template engine borrows the syntax style similar to Django templates, allowing us to directly output variables in template files (using `{{

2025-11-08

How to remove leading and trailing spaces or specific characters from a string in the template using a filter?

In website content display, we often encounter situations where there are extra spaces, line breaks at the beginning and end of strings, or specific characters need to be deleted.These seemingly minor details can affect the layout and aesthetic of the page, the accuracy of data display, and even have an adverse effect on search engine optimization (SEO).AnQiCMS is a powerful template engine that provides rich filter functions, which can help us easily and elegantly handle these strings, making your content more accurate and professional.AnQiCMS's template syntax is concise and intuitive, it draws on Django

2025-11-08

How to automatically parse URL strings to clickable `<a>` tags in the article body or description?

In daily website content creation and management, we often need to embed some links in the article body or description, such as referencing external resources, pointing to product pages, or other related articles.If these URLs are only displayed in plain text, users will have to manually copy and paste them into the browser, which undoubtedly will greatly reduce their user experience.幸运的是,AnQiCMS 内置了非常实用的功能,可以自动将这些 URL 字符串智能识别并转换为可点击的 `a` 标签,让网站内容更加友好和便捷。This function mainly through

2025-11-08

How to retrieve and display user group details, such as group name, level, and purchase price, for a membership system?

Today in the operation of the website, building an efficient member system is crucial for content monetization, user stickiness cultivation, and community construction.AnQiCMS (AnQiCMS) provides a solid foundation for building such a system with its flexible design and rich features.Among them, the fine management of user groups is the core of the member system's operation, which allows us to provide differentiated service experiences based on the different identities and rights of users.### User Group Management in AnQi CMS: Basics and Value AnQi CMS built-in user group management function

2025-11-08

How to reuse common HTML fragments in a template by using the `include` tag or define reusable code blocks by `macro`?

In the development and maintenance of website templates, we often encounter the need to reuse HTML code snippets or logical structures.If you always copy and paste, it is not only inefficient, but also once you need to modify it, you have to repeat the operation in multiple places, which is very prone to errors.AnQi CMS knows this point, it provides a template engine that adopts Django's syntax, through `include` tags and `macro` macro functions, allowing us to easily achieve code reuse, greatly enhancing the maintainability and development efficiency of templates.### Reuse the public HTML fragment: `include`

2025-11-08

How to set up image resource management in AnQi CMS and support batch regeneration of thumbnails in different sizes?

In website operation, images are not only an important part of the content, but also a key factor affecting page loading speed and user experience.Efficient image management can greatly enhance the performance and maintainability of a website.AnQiCMS (AnQiCMS) is well-versed in this field, providing users with comprehensive image resource management functions, especially excelling in thumbnail settings and batch processing, making image operations more convenient and flexible.### Core Feature Overview: AnqiCMS Image Management System AnqiCMS Image Resource Center is a collection of upload, classification, editing

2025-11-08