# Nested Comments Thread (with Like and Reply)

## Overview

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2cOIxr2OqJuRmlfKq%2Fimage.png?alt=media\&token=946fedeb-49e0-45fc-b364-e853d42ba128)

This block contains a list of comments created by different users. Each user can create a new comment, reply to, or like a parent comment. This block (and its comments database object) can be connected to any data object in your database (e.g., a topic, a product, or a post). Admins (or users with admin access) can manage the comments section by hovering over a comment and clicking on the ellipsis menu to delete the comment. By default, the widget allows for three levels of comments.&#x20;

## Structure

When this block is added to a page, it is placed within a group called **Blocks container 860 (do not rename)** on the page. This group contains the responsive settings for all blocks.

* **nestedcomments\_template**\
  This reusable element contains all of the logic and UI for the nested comments module. It contains four main groups:<br>
  * **Group Parent message input**\
    This group contains the multiline input for posting a parent `Comment`. Clicking on **Button Parent POST** will most the text in **MultilineInput Parent Comment** as a parent `Comment`.<br>
  * **RepeatingGroup Parent comment**\
    This repeating group displays all parent `comments` posted by users (where the parent comment is empty).
    * **RepeatingGroup Child comment** displays all children comments (where the parent comment is parent group's comment).
    * Clicking on **Text Parent reply button** will show **Group Child message input\_t-comment** and allow the user to reply to a parent `comment`.
      * Clicking on **Button Child Reply** will post the `comment` underneath the parent `Comment`.
    * Clicking on **Text Parent like button** and **Text Child like button** will show **Popup likes**.
    * Clicking on **Group Parent fav comment\_t-comment** or **Group Child fav comment\_t-comment** will like/unlike the comment.
    * Clicking on **Group Parent menu\_t-comment** and **Group Child menu\_t-comment** will show a menu to delete a `Comment`.
      * You should add another statement to the existing conditional statements on these groups: *...and Current user's Role is App Admin*<br>
  * **Group Main no comments**\
    This group will be visible when **RepeatingGroup Parent comment's** list of comments count is 0.<br>
  * **Popup Likes**\
    This popup shows a list of users who have liked a `comment`.

## How to set up

* Add a field to the `Comment` data type that represents the object on which you want users to comment. For example, if you want users to comment on products, you should add a `Product` field.

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-LbzT1_Nv9ROKl9Gt5jw%2F-LbzWjPZiiLmw8oGahZx%2Fimage.png?alt=media\&token=0b34150f-1f6d-4dc5-8e11-11a1fed306a5)

* Make a copy of the **nestedcomments\_template** reusable. This preserves the original reusable element aded by the extension, incase you need to link comment functionality to multiple data types within your application. <br>
* Modify the copied reusable's type of content from empty to the custom object for which you want to show comments. For example, if you are building a marketplace where Users can comment on different Products, you could make the copied reusable's group type `Product`.&#x20;

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2ewnBJObKAecDEzv0%2Fnested_comments.png?alt=media\&token=7d8e7a52-902f-442b-baa3-f537cf5d9a17)

* Next, we can add a "Product" field (type: Product, list: no) to the "t-Comment" data type, and modify the data source for **RepeatingGroup Parent comment** to include any needed filters. In the marketplace example, the data source will display comments that are linked to the `Product`  object that is the data source of the reusable.

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2fW2rwkkbX_Y7V-Zp%2Fconstraint_nested_comments.png?alt=media\&token=b4906ceb-0dc4-4e68-868d-28c83871bebc)

* Modify the three actions that run when the **Button Parent POST,** **Button Child REPLY (second level), and Button Child REPLY (third level) elements** are clicked to link the`Comment` created to the relevant object. In this example, we are linking the `Product` that's displayed in the reusable to each Comment by storing the `Product` object in each `Comment`'s `Product` field.

**Button Child REPLY (second level)**

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2jbW1e5pRJTfeyjBl%2Freply.png?alt=media\&token=7154e2ac-c9c3-40af-b9bd-9044a5bec7eb)

**Button Child REPLY (third level)**

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2i_x7qfo8WB8q_qRa%2Fbutton-2.png?alt=media\&token=7e349569-1532-4720-91f8-529442303068)

**Button Parent POST**&#x20;

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2icUghUwM9wzkZPy6%2Fbutton-3.png?alt=media\&token=748f6964-5ab8-450b-aaa1-604581157db0)

* Add a data source whenever you use the **nestedcomments\_template** reusable element as an instance on a page.&#x20;

![](https://1483599141-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LbzMeM9XfnblRd78nga%2F-MW2Nu5J_B1EsyCFPRA7%2F-MW2gZO2q10jTMxHdNaQ%2Fproduct-page-example.png?alt=media\&token=054eeb60-59d2-4b7a-b74d-a63d6adcd1ca)
