Displaying Comments

The {{ meerkat:comments }} tag renders published comments for the current thread. Each root comment contains its replies in children.

#Minimum example

1{{ meerkat:comments }}
2 <article id="comment-{{ id }}">
3 <header>
4 <strong>{{ author_name }}</strong>
5 <time>{{ created_at }}</time>
6 </header>
7 <div>{{ comment_html }}</div>
8
9 {{ if has_replies }}
10 <div class="replies">
11 {{ children }}
12 <article id="comment-{{ id }}">
13 <strong>{{ author_name }}</strong>
14 <div>{{ comment_html }}</div>
15 </article>
16 {{ /children }}
17 </div>
18 {{ /if }}
19 </article>
20{{ /meerkat:comments }}
1<s-meerkat:comments>
2 <article id="comment-{{ $id }}">
3 <header>
4 <strong>{{ $author_name }}</strong>
5 <time>{{ $created_at }}</time>
6 </header>
7 <div>{!! $comment_html !!}</div>
8
9 @if ($has_replies)
10 <div class="replies">
11 @foreach ($children as $child)
12 <article id="comment-{{ $child['id'] }}">
13 <strong>{{ $child['author_name'] }}</strong>
14 <div>{!! $child['comment_html'] !!}</div>
15 </article>
16 @endforeach
17 </div>
18 @endif
19 </article>
20</s-meerkat:comments>

{{ comment_html }} contains sanitized HTML. Escape or sanitize the raw {{ comment }} value before rendering it.

#Parameters

Parameter Default Notes
thread / from_thread current context Choose one thread, a pipe-separated list ("a|b"), or "*" for every thread. See How Meerkat finds the thread and Querying multiple threads.
site / locale current site Restrict to one site. * includes all sites.
include_unpublished false Include pending, rejected, and spam comments. Requires view comments.
include_tombstones false Include removed comments as placeholders. Requires view comments.
include_tombstone_replies false Include descendants of removed comments. Use with include_tombstones. Requires view comments.
include_trashed false Include soft-deleted comments. Requires view comments. See Soft-Deleted Comments.
show_future true Include comments with a future created_at value.
show_past true Include comments created before the current time.
limit none Maximum number of root comments to return.
offset none Number of root comments to skip.
paginate none Page size for paginated results. true uses limit as the page size. See Pagination.
order_by none Sort root comments. The default is created_at:asc, then id:asc. Separate multiple criteria with a pipe: created_at:desc|name:asc.

Statamic conditions also work:

1{{ meerkat:comments is_published:is="true" comment_text:contains="hello" }}
1<s-meerkat:comments is_published:is="true" comment_text:contains="hello" />

See Template overview: Filtering.

#Querying multiple threads

By default, the tag uses the current thread. Pass thread to read comments from several threads:

1{{ meerkat:comments thread="blog/first|blog/second" order_by="created_at:desc" }}
2 <article><strong>{{ author_name }}</strong>: {{ comment_html }}</article>
3{{ /meerkat:comments }}
4
5{{ meerkat:comments thread="*" paginate="20" order_by="created_at:desc" }}
6 {{ comments }}
7 <article><strong>{{ author_name }}</strong>: {{ comment_html }}</article>
8 {{ /comments }}
9 {{ paginate }} ... {{ /paginate }}
10{{ /meerkat:comments }}
1<s-meerkat:comments thread="blog/first|blog/second" order_by="created_at:desc">
2 <article><strong>{{ $author_name }}</strong>: {!! $comment_html !!}</article>
3</s-meerkat:comments>
4
5<s-meerkat:comments thread="*" paginate="20" order_by="created_at:desc">
6 @foreach ($comments as $comment)
7 <article><strong>{{ $comment['author_name'] }}</strong>: {!! $comment['comment_html'] !!}</article>
8 @endforeach
9</s-meerkat:comments>

Visitors receive only published comments that are not spam or removed. When using thread="*", add a condition to limit the results to one collection:

1{{ meerkat:comments thread="*" collection:is="blog" }} ... {{ /meerkat:comments }}
1<s-meerkat:comments thread="*" collection:is="blog"> ... </s-meerkat:comments>

Each top-level comment includes all its replies. Use pagination when requesting many threads. {{ meerkat:comment_count thread="*" }} counts comments across all threads; thread_stats and comments_enabled use one thread.

#Pagination

1{{ meerkat:comments paginate="20" }}
2 {{ comments }}
3 ...
4 {{ /comments }}
5
6 {{ paginate }}
7 {{ if prev_page }}<a href="{{ prev_page }}">Previous</a>{{ /if }}
8 Page {{ current_page }} of {{ total_pages }}
9 {{ if next_page }}<a href="{{ next_page }}">Next</a>{{ /if }}
10 {{ /paginate }}
11{{ /meerkat:comments }}
1<s-meerkat:comments paginate="20">
2 @foreach ($comments as $comment)
3 ...
4 @endforeach
5
6 @if ($paginate['prev_page'])<a href="{{ $paginate['prev_page'] }}">Previous</a>@endif
7 Page {{ $paginate['current_page'] }} of {{ $paginate['total_pages'] }}
8 @if ($paginate['next_page'])<a href="{{ $paginate['next_page'] }}">Next</a>@endif
9</s-meerkat:comments>

With pagination, iterate the {{ comments }} collection. See Comment variables for the available fields.

Pagination applies to top-level comments. Each one still contains all its replies. To paginate replies separately, use GET /api/meerkat/threads/{id}/children/{parent_id}.

#Show content based on the viewer

Use the current_user.* block to render author-aware controls:

1{{ meerkat:comments }}
2 <div>{{ comment_html }}</div>
3
4 {{ if current_user:is_author }}
5 <small>This is your comment.</small>
6 {{ /if }}
7
8 {{ if current_user:can_edit or current_user:is_author }}
9 <a href="...">Edit</a>
10 {{ /if }}
11
12 {{ if current_user:can_report_spam }}
13 <button>Report as Spam</button>
14 {{ /if }}
15{{ /meerkat:comments }}
1<s-meerkat:comments>
2 <div>{!! $comment_html !!}</div>
3
4 @if ($current_user['is_author'])
5 <small>This is your comment.</small>
6 @endif
7
8 @if ($current_user['can_edit'] || $current_user['is_author'])
9 <a href="...">Edit</a>
10 @endif
11
12 @if ($current_user['can_report_spam'])
13 <button>Report as Spam</button>
14 @endif
15</s-meerkat:comments>

#Deleted comments

Control Panel deletion creates a restorable tombstone and hides its replies. Authorized templates can render placeholders with include_tombstones="true" and replies with include_tombstone_replies="true".

See Soft-Deleted Comments for examples and permanent-deletion options.

Was this page helpful?