Comment#

Whenever you're dealing with a comment in your template, you're actually working with a Comment object.

Attributes#

AttributeDescription
idID of the comment.
ownerIdThe element ID this comment was made on (Entry, Asset, etc).
ownerSiteIdThe element site ID this comment was made on (Entry, Asset, etc).
ownerThe element this comment was made on (Entry, Asset, etc).
userIdUser (opens new window) ID for the author of a comment.
authorUser (opens new window) for the author of a comment. For guest, this will still return a new User, with their email, first/last name attributes populated.
parentComment object of any parent. Only applicable when replying to another comment. For new comments, this will be null.
statusThe status of this comment. Available values are approved, pending, spam, trashed.
nameName of the commenter. Guest users only.
emailEmail address of the commenter. Guest users only.
urlThe URL that this comment was made from.
ipAddressCommenters IP Address.
userAgentCommenters User Agent.
commentThe comment text.

Methods#

MethodDescription
isGuest()Returns true/false if a comment was made by an guest user.
getTimeAgo()Returns a human-friendly string of how long ago a comment was made, ie: 2 min ago.
getExcerpt(start, length)Returns an excerpt of the comment. You can also supply parameters to control length.
hasFlagged()Whether the user has already flagged a comment.
isFlagged()If a comment receives more than a certain amount of flags, isFlagged will be true. This limit is configurable through the plugin settings.
getFlags()Returns the number of flags made on this comment.
getVotes()Returns the resulting number of votes made on this comment. This will be the result of upvotes subtracting downvotes.
getAllVotes()Returns the number of votes made on this comment. This will count upvotes and downvotes.
getUpvotes()Returns the number of upvotes made on this comment.
getDownvotes()Returns the number of upvotes made on this comment.
isPoorlyRated()If a comment receives more than a certain amount of downvotes, isPoorlyRated will be true. This limit is configurable through the plugin settings.

Permission Methods#

There are a number of methods for checking if the commenter can do certain tasks. Additionally, you can pass in any Configuration settings to test against.

MethodDescription
canReply()Returns true/false if the current user can reply to other comments.
canEdit()Returns true/false if the current user can edit this comment.
canTrash()Returns true/false if the current user can trash this comment.
canVote()Returns true if the user can vote on a comment. Must be a registered user and cannot be their own comment.
canFlag()Returns true if the user can flag a comment. Must be a registered user and cannot be their own comment.

You can also use a shorthand method if you prefer:

{{ can('reply') }}
{{ can('edit') }}
{{ can('trash') }}
{{ can('vote') }}
{{ can('flag') }}

Deleting a comment#

You can delete a comment using a POST request to an action controller, and the following template code. You must supply a commentId and siteId in your form.

<form role="form" method="post" accept-charset="UTF-8">
    <input type="hidden" name="action" value="comments/comments/trash">
    <input type="hidden" name="siteId" value="{{ comment.siteId }}">
    <input type="hidden" name="commentId" value="{{ comment.id }}">
    {{ csrfInput() }}

    <button type="submit">{{ 'Delete' | t('comments') }}</button>
</form>

Previous ← Comment Queries Next Flag →