|
| 1 | +--- |
| 2 | +title: resComments |
| 3 | +description: Nested comments with pagination for MODX 3 |
| 4 | +logo: https://file.modx.pro/files/a/9/4/a9499643bf99f8080a37405836d0a504.png |
| 5 | +author: Romanov Pavel |
| 6 | +modstore: https://modstore.pro/packages/utilities/rescomments |
| 7 | +--- |
| 8 | + |
| 9 | +# resComments |
| 10 | + |
| 11 | +Nested comments with pagination for MODX 3 resources. |
| 12 | + |
| 13 | +## Key features |
| 14 | + |
| 15 | +- Unlimited nesting depth |
| 16 | +- Multiple instances per page |
| 17 | +- Post rating (“star” rating) |
| 18 | +- Reply ratings and scoring |
| 19 | +- WYSIWYG editor [Pell](https://github.com/jaredreich/pell) |
| 20 | +- Schema.org markup |
| 21 | +- Users can delete their own comments |
| 22 | +- Email notifications to the site manager, post author, and comment authors about replies |
| 23 | +- Pagination (with pdoPage) |
| 24 | +- Works without jQuery (except when used together with pdoPage) |
| 25 | +- Configurable toast notifications |
| 26 | +- Manager custom component with search, filtering, and create / delete / edit (including multi-level replies) |
| 27 | +- “Comments” tab for resources with selected templates |
| 28 | +- “Comments” tab for resources with selected IDs |
| 29 | + |
| 30 | +## System settings |
| 31 | + |
| 32 | +| Parameter | Description | Default | |
| 33 | +| :--- | :--- | :--- | |
| 34 | +| **rc_antispam_field** | Anti-spam field (must be empty) | comment_subject | |
| 35 | +| **rc_autopublish** | Auto-publish without moderation | 1 | |
| 36 | +| **rc_notifications** | Script for toast notifications.<br>Supports [Notyf](https://github.com/caroso1222/notyf) and [SweetAlert2](https://modstore.pro/packages/alerts-mailing/sweetalert2) (must be installed). You can also set miniShop3, FetchIt, or AjaxForm to reuse those components’ notifications (if installed). | Notyf | |
| 37 | +| **rc_js_url** | Path to the JS file from the site root. | `{assets_url}components/rescomments/js/web/default.min.js` | |
| 38 | +| **rc_css_url** | Path to the CSS file from the site root. | `{assets_url}components/rescomments/css/web/default.min.css` | |
| 39 | +| **rc_tab_tpl** | Template IDs for which to show the “Comments” tab, comma-separated.<br>Set `all` to show the tab for every template; leave empty to hide it. | | |
| 40 | +| **rc_tab_resources** | Resource IDs for which to show the “Comments” tab, comma-separated. | | |
| 41 | +| **rc_email_send_createdby** | Notify the resource author about new comments (by `createdby`). | No | |
| 42 | +| **rc_email_send_manager** | Notify managers about new comments. | Yes | |
| 43 | +| **rc_email_send_user** | Notify users about replies to their comments. | Yes | |
| 44 | +| **rc_email_subject_createdby** | Email subject to the author about a new comment on their post | New comment on your post | |
| 45 | +| **rc_email_subject_manager** | Email subject to managers about a new comment | New comment | |
| 46 | +| **rc_email_subject_user** | Email subject to the user about a reply to their comment | Reply to your comment | |
| 47 | +| **rc_email_tpl_createdby** | Chunk template for the email to the post author. | `rc_tpl_email_author` | |
| 48 | +| **rc_email_tpl_manager** | Chunk template for the email to managers | `rc_tpl_email_manager` | |
| 49 | +| **rc_email_tpl_user** | Chunk template for the email to the user | `rc_tpl_email_user` | |
| 50 | + |
| 51 | +## resComments snippet |
| 52 | + |
| 53 | +Renders comments for a resource and loads the required scripts and styles. Call it uncached: |
| 54 | + |
| 55 | +``` |
| 56 | +[[!resComments]] |
| 57 | +``` |
| 58 | + |
| 59 | +With Fenom: |
| 60 | + |
| 61 | +``` |
| 62 | +{'!resComments' | snippet : []} |
| 63 | +``` |
| 64 | + |
| 65 | +With **pdoPage**: |
| 66 | + |
| 67 | +``` |
| 68 | +<div id="pdopage"> |
| 69 | + <div class="rows"> |
| 70 | + [[!pdoPage? |
| 71 | + &element=`resComments` |
| 72 | + ]] |
| 73 | + </div> |
| 74 | + [[!+page.nav]] |
| 75 | +</div> |
| 76 | +``` |
| 77 | + |
| 78 | +Snippet properties (override system settings). |
| 79 | + |
| 80 | +| Property | Description | Default | |
| 81 | +| :--- | :--- | :--- | |
| 82 | +| **docid** | Resource ID. | Current | |
| 83 | +| **topic** | Topic (thread). Must be unique site-wide. | comments-## (## — resource ID) | |
| 84 | +| **allowAll** | All visitors can add comments (`0` — logged-in only). | 1 | |
| 85 | +| **maxLevel** | Maximum nesting depth for comments. | 50 | |
| 86 | +| **maxShiftLevel** | Maximum depth after which replies are no longer visually indented. | 10 | |
| 87 | +| **title** | Comments block heading. | `[[%rescomments_block_title]]` | |
| 88 | +| **addText** | Label on the “add comment” button. | `[[%rescomments_add]]` | |
| 89 | +| **replyText** | Label on the “reply” button. | `[[%rescomments_reply]]` | |
| 90 | +| **required** | Required form fields. | `name, email, text, agree` | |
| 91 | +| **autopublish** | Publish comments and replies immediately after submission | 1 | |
| 92 | +| **antispamField** | Anti-spam field. | `comment_subject` | |
| 93 | +| **deleteTime** | Seconds during which the user can delete their own comment (if it has no reply). | 600 | |
| 94 | +| **hideReplies** | Hide replies when the page loads.<br>Only top-level comments are shown. If there are replies, their count and an “Expand” button are shown. | 0 | |
| 95 | +| **sortby** | Sort order as JSON. | `{"createdon":"DESC"}` | |
| 96 | +| **limit** | Items per page. | 10 | |
| 97 | +| **offset** | Offset from the start. | 0 | |
| 98 | +| **Templates** | | | |
| 99 | +| **tpl** | Chunk for a single comment. | `rc_tpl_comment` | |
| 100 | +| **tplWrapper** | Chunk wrapping all comments. | `rc_tpl_wrapper` | |
| 101 | +| **tplForm** | Chunk for the add-comment form. | `rc_tpl_form` | |
| 102 | +| **tplDelete** | Chunk for the delete button. | `rc_tpl_delete` | |
| 103 | +| **tplRepliesInfo** | Chunk for the reply count and “Expand” control. | `rc_tpl_replies_info` | |
| 104 | +| **Notifications** | | | |
| 105 | +| **emailTo** | Manager addresses | `[[++emailsender]]` | |
| 106 | +| **emailFrom** | Notification sender | `[[++site_name]]` | |
| 107 | +| **emailManager** | Notify managers about new comments. | 1 | |
| 108 | +| **emailAuthor** | Notify post authors about new comments. | 1 | |
| 109 | +| **emailUser** | Notify comment authors about replies to their comments. | 0 | |
| 110 | +| **emailSubjectAuthor** | Email subject to the author about a new comment on their post. | New comment on your post | |
| 111 | +| **emailSubjectManager** | Email subject to managers about a new comment. | New comment | |
| 112 | +| **emailSubjectUser** | Email subject to the user about a reply to their comment. | Reply to your comment | |
| 113 | +| **emailTplAuthor** | Chunk for the email to the post author. | `rc_tpl_email_author` | |
| 114 | +| **emailTplManager** | Chunk for the email to managers. | `rc_tpl_email_manager` | |
| 115 | +| **emailTplUser** | Chunk for the email to the user. | `rc_tpl_email_user` | |
| 116 | + |
| 117 | +Chunks support standard MODX tags and Fenom. |
| 118 | +Bundled templates are styled for Bootstrap. |
| 119 | + |
| 120 | +## Plugin events |
| 121 | + |
| 122 | +| Event | Description | |
| 123 | +| --- | --- | |
| 124 | +| **rcOnBeforeCreateComment** | Fired before a comment is created.<br>Receives `$data` — the array submitted from the form.<br>You may modify and return it with `$modx->event->returnedValues = $data;` | |
| 125 | +| **rcOnAfterCreateComment** | Fired after a comment is created. Receives `$object` — the new comment object. | |
0 commit comments