How to judge whether the comment (`Status`) in the AnQiCMS template has passed the review and be displayed differently?

Calendar 👁️ 62

As an experienced website operations expert, I fully understand the importance of the comment system for user interaction and content ecology on the website.In a powerful content management system like AnQiCMS, flexibly controlling the display of comments, especially differentiating based on the review status, is a key link to improve user experience and maintain the quality of website content.commentListTag to judge the comment'sStatusfield, and implement intelligent distinction display.

Review status: Core mechanism of AnQiCMS

In AnQiCMS, every user submitted comment has oneStatus(Status) field, it is like a traffic light, indicating whether this comment has passed the administrator's review.This mechanism is crucial for the security and compliance of website content, as it effectively prevents the direct posting of spam, sensitive words, or inappropriate remarks.

Specifically, incommentListEach item returned by theitem),StatusThe value of the field usually has two types:

  • Status = 1: Indicates that this comment has passed the review and can be displayed normally on the website front page.
  • Status = 0This comment is pending review or has been rejected by the administrator.For the sake of website content quality, such comments should not be fully public or may need to be prompted to users in a special way.

UnderstoodStatusThe meaning of the field, we can provide users with a more refined and friendly comment display experience at the template level.

Skillfully using conditional judgment to achieve differentiated display.

AnQiCMS's template system, similar to the Django template engine syntax, provides powerful conditional judgment capabilities. This means we can easilycommentListiterate over, based onitem.StatusThe value determines how each comment is rendered.

Suppose we are editing the comment list page (usuallycomment/list.htmlFile, as mentioned in the AnQiCMS template directory agreement, the following is a classiccommentListTag usage scenarios, we will add the logic ofStatusjudgment:

{% commentList comments with archiveId=archive.Id type="page" limit="10" %}
    {% for item in comments %}
    <div class="comment-item {% if item.Status != 1 %}comment-pending{% endif %}">
      <div class="comment-meta">
        <span class="user-name">
          {% if item.Status != 1 %}
          <!-- 未审核的评论,可以显示部分信息或提示,同时可以截断用户名称以保护隐私 -->
          待审核用户:{{item.UserName|truncatechars:4}}...
          {% else %}
          {{item.UserName}}
          {% endif %}
        </span>
        {% if item.Parent %}
        <!-- 如果是回复评论,也需要检查父级评论的审核状态 -->
        <span>回复</span>
        <span class="parent-user-name">
          {% if item.Parent.Status != 1 %}
          待审核用户:{{item.Parent.UserName|truncatechars:4}}...
          {% else %}
          {{item.Parent.UserName}}
          {% endif %}
        </span>
        {% endif %}
        <span class="comment-time">{{stampToDate(item.CreatedTime, "2006-01-02 15:04")}}</span>
      </div>
      <div class="comment-content">
        {% if item.Parent %}
        <!-- 父级评论内容展示,同样需要判断审核状态 -->
        <blockquote class="parent-comment-quote">
          {% if item.Parent.Status != 1 %}
          <p class="pending-message">原评论正在审核中,仅展示部分:{{item.Parent.Content|truncatechars:15}}...</p>
          {% else %}
          {{item.Parent.Content|safe}}
          {% endif %}
        </blockquote>
        {% endif %}
        {% if item.Status != 1 %}
          <p class="pending-message">您的评论正在审核中,请耐心等待。</p>
          <p class="pending-content">(内容部分隐藏或截断:{{item.Content|truncatechars:20}}...)</p>
        {% else %}
          {{item.Content|safe}}
        {% endif %}
      </div>
      <div class="comment-actions">
        <a class="item" data-id="praise">赞(<span class="vote-count">{{item.VoteCount}}</span>)</a>
        <a class="item" data-id=reply>回复</a>
      </div>
    </div>
    {% endfor %}
{% empty %}
    <p>暂无评论。</p>
{% endcommentList %}

In the above code example, we adopted the following strategies to achieve distinct display:

  1. Add a special CSS class for unreviewed commentsIndivBy the tag, we use{% if item.Status != 1 %}comment-pending{% endif %}If the comment does not pass the reviewStatusand is not equal to 1, it is set to 0), addcomment-pendingThis CSS class.This way, we can define special styles for such comments in CSS, such as grayscale display, semi-transparent, or add a border hint to distinguish them visually from reviewed comments.
  2. Modify the name of the reviewer: For unreviewed comments, we will prefix the commenter's name with "Pending Review User" and use|truncatechars:4Filter (from AnQiCMS with more filter features) truncates usernames to protect user privacy and implies their status.
  3. Display review prompt informationIn the comment content area, if the comment does not pass the review, we will no longer display the full content directly, but instead replace it with 'Your comment is being reviewed, please wait patiently.'Such a friendly reminder, and it can also truncate the display of original comments to avoid information leakage.
  4. Handle the review status of the parent comment (reply to the comment): Considering that the comment may have a reply relationship,item.Parentthe object also includesStatusfield. In order to maintain the completeness and accuracy of the comment chain, we also judge the parent comment'sStatusto ensure the reply

Related articles

How to conditionally display the 'Previous' and 'Next' buttons in the `pagination`?

As an experienced website operation expert, I am willing to analyze the conditional display techniques of the pagination navigation buttons in AnQi CMS in detail.AnQi CMS is known for its efficiency and flexibility, its template engine provides powerful functions, allowing us to easily achieve both beautiful and practical page interactions.In website content management, pagination is an indispensable element, and how to intelligently display the "Previous Page" and "Next Page" buttons is directly related to the smoothness of the user's browsing experience.### SecureCMS

2025-11-06

In the `pagination` tag, how to determine if the current page is the first or last page to control the style?

As an experienced website operations expert, I know the importance of a powerful and flexible content management system for the success of a website.AnQiCMS leverages the efficiency of the Go language and its deep consideration for content operation, providing us with many conveniences.Today, let's delve into the wonderful use of the `pagination` tag in AnQiCMS, especially how to accurately judge whether the current page is the first page or the last page, thereby flexibly controlling the style to create a smoother and more intuitive navigation experience for users.

2025-11-06

How to conditionally output the standard link according to the `CanonicalUrl` tag in AnQiCMS templates?

Hello! As an experienced website operations expert, I fully understand that in daily work, we not only need to pay attention to the quality of the website content, but also to the impact of technical details on SEO.The canonical URL is one of the crucial details that can effectively solve the problem of duplicate website content, concentrate page authority, and thus improve search engine rankings.Today, let's delve deeply into how to intelligently and elegantly output standard links based on the existence or absence of the `CanonicalUrl` field within the `tdk` tag in AnQiCMS templates

2025-11-06

How to determine if the `linkList` friendship link tag list is empty to avoid displaying an empty tag?

As an experienced website operations expert, I have accumulated rich experience in content management and template optimization in AnQiCMS.I know well that a smooth, beautiful and quick-loading website cannot be separated from the meticulous refinement of every detail.Today, let's delve deeply into an issue that is often overlooked in template development but is crucial for user experience and page neatness: how to avoid displaying redundant empty tags when the `linkList` friendship link tag list is empty.Avoid displaying empty tags: AnQi CMS

2025-11-06

How to determine if a comment in `commentList` has a parent comment (`Parent`) and display the reply structure?

As an experienced website operations expert, I fully understand how to effectively display user comments in content management, especially comments with reply structures, which are crucial for enhancing user interaction and website activity.AnQiCMS (AnQiCMS) relies on its powerful template engine and flexible data tags to make this requirement easily achievable.Today, let's delve into how to cleverly judge whether a comment has a parent comment in the AnQiCMS `commentList` tag and elegantly present a clear reply structure.

2025-11-06

How to dynamically add a required asterisk or hint based on the `Required` property of the `guestbook` form label?

As an experienced website operation expert, I know that every detail can affect user experience and operation efficiency.When building a website, forms are an important part of interacting with users, and clear, friendly form design is the key to improving conversion rates.AnQiCMS (AnQiCMS) with its flexible template engine and powerful backend management features, has provided us with great convenience, especially in handling scenarios such as message forms that require users to fill in information.Today, let's delve deeply into a seemingly simple but extremely practical skill: how to use the `Required` field of the back-end field

2025-11-06

How to render different input controls (such as text, radio, checkbox) in the `guestbook` form based on the `Type` attribute?

As an experienced website operations expert, I know that a flexible and versatile content management system is the foundation of website success.AnQiCMS (AnQiCMS) with its excellent flexibility and powerful customization capabilities has become an invaluable tool in our hands.Today, let's delve deeply into a very practical topic in actual operation: how to intelligently render different input controls, such as text boxes, radio buttons, or checkboxes, in the `guestbook` form of Anqi CMS according to the preset field types in the background.This is not just an implementation at the technical level

2025-11-06

How to determine if a custom field exists or has a value in `archiveParams` before displaying it?

As an experienced website operation expert, I deeply know the powerful potential of AnQiCMS (AnQi CMS) in content management and website optimization.The flexible content model and customizable fields provide great convenience for us to build highly personalized websites.However, how to elegantly handle these dynamically generated custom fields in template design, ensuring that they are displayed only when they exist or have a value, is the key to improving template quality and user experience.

2025-11-06