Filtering Comment Threads

Version 1.5.8+
6 min read

You are viewing the documentation for Meerkat version 1 for Statamic 2. The latest version is Meerkat 2 for Statamic 3.

Read v2 docs

The content of this guide requires version 1.5.85 or higher of Meerkat for Statamic 2.

Meerkat v1.5.85 for Statamic 2 added the filter parameter to the meerkat:responses tag, which allows you to quickly filter which comments will make it to your reader's screens. The filter parameter works by providing the name of the filter, or filters, that you would like to apply to the comments before they are made available to your template.

For example, if we wanted to show comments that were only left by authenticated Statamic users, we could supply the user:from_auth filter like so:

{{ meerkat:responses filter="user:from_auth(true)" }}

{{ /meerkat:responses }}

You may have noticed that, in the previous example, the from_auth filter can accept parameters; it's true! Many of the default filters allow you to pass in some type of parameter. We could have rewritten the previous example like so to show comments left by anonymous site users:

{{ meerkat:responses filter="user:from_auth(false)" }}

{{ /meerkat:responses }}

A quick note on tags: In this guide, you may see both {{ meerkat:responses }} and {{ meerkat:all-comments }} used. For the most part, they are completely interchangeable with filters, with some exceptions.

Default Filters

Currently, Meerkat offers the following filters as part of its core package:

Filter Description Default
is:spam(<true/false>) Returns all comments that are either spam, or not spam. false
is:published(<true/false>) Returns all comments that are either published, or not published. true
thread:in(<list_of_thread_ids>) Returns comments who belong to any of the threads in the provided list. Empty List []
thread:not_in(<list_of_thread_ids) Returns comments who do not belong to and of the threads in the provided list. Empty List []
user:from_auth(<true/false>) Returns comments based on whether they were left by an authenticated user. false
user:in(<list_of_user_ids>) Returns comments left by authenticated users who are in provided user list. Empty List []
user:not_in(<list_of_user_ids>) Returns comments left by authenticated users who are not in the provided user list. Empty List []

Using Parameters

The most straightforward way to use filter parameters is to supply them inline:

This example would display comments from the thread that is supplied:

{{ meerkat:all-comments filter="thread:in(d50b404b-19b1-433b-af8b-9243c4047ce3)" }}

{{ /meerkat:all-comments }}

However, to keep things clean, we can reference other parameters:

{{ meerkat:all-comments filter="thread:in(threadsToInclude)" threadsToInclude="d50b404b-19b1-433b-af8b-9243c4047ce3" }}

{{ /meerkat:all-comments }}

Any "list" parameter can accept multiple values, which are supplied as comma-delimited list:

{{ meerkat:all-comments filter="thread:in(threadsToInclude)"
	threadsToInclude="d50b404b-19b1-433b-af8b-9243c4047ce3, e8c2c670-1c0e-4406-9b75-b4bcc325cc95" }}

{{ /meerkat:all-comments }}

You may also use Antler's template variables:

{{ meerkat:all-comments filter="thread:in(@{ id })" }}

{{ /meerkat:all-comments }}

Chaining Filters

More than one filter may be applied to the comments that will be returned to your template. Multiple filters are separated by a pipe |. The results of each filter are passed as input to the next filter.

The following example would filter the comments to only display comments from the provided thread and have not been left by an authenticated Statamic user:

{{ meerkat:all-comments filter="thread:in(d50b404b-19b1-433b-af8b-9243c4047ce3)|user:from_auth(false)" }}

{{ /meerkat:all-comments }}

Internally, Meerkat will:

  1. Find all comments in the thread d50b404b-19b1-433b-af8b-9243c4047ce3
  2. Find all comments from step 1 that were left by anonymous users

If we reversed the order like so:

{{ meerkat:all-comments filter="user:from_auth(false)|thread:in(d50b404b-19b1-433b-af8b-9243c4047ce3)" }}

{{ /meerkat:all-comments }}

Meerkat would instead take these actions:

  1. Find all comments that were left by anonymous users (from all threads)
  2. Find all comments in step 1 that are in the thread d50b404b-19b1-433b-af8b-9243c4047ce3

Special Constants

Some filters that accept lists offer special constants to make things a little easier.

The following example will automatically get the current Statamic user's ID, if available:

{{ meerkat:responses filter="user:in(*current*)" }}

{{ /meerkat:responses }}

The following example will automatically get the current thread ID, if available:

{{ meerkat:all-comments filter="thread:in(*current*)" }}

{{ /meerkat:all-comments }}

The special constants may be combined with other values:

{{ meerkat:all-comments filter="thread:in(*current*, d50b404b-19b1-433b-af8b-9243c4047ce3)" }}

{{ /meerkat:all-comments }}

Looking for more flexibility and options? Check out the Advanced Thread Filtering guide.