Handling Soft Deleted Comments

Front End
Version 1.5.8+
3 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

One thing to be aware of when building the templates is that Meerkat add-ons can "soft delete" a comment; this means that the comment will still exist. By default, Meerkat will not include these comments when using the {{ meerkat:responses }} tag. However, we can display them by passing a value of true for the show_hidden parameter:

{{ meerkat:responses show_hidden="true" }}
    <div class="media">
        <div class="media-body">
            <h4 class="media-heading">{{ name }}</h4>
            {{ comment }}
        </div>
    </div>
{{ /meerkat:responses }}

We can react to this in our templates by checking the is_deleted value:

{{ meerkat:responses show_hidden="true" }}
    <div class="media">
        <div class="media-body">
            <h4 class="media-heading">{{ name }}</h4>
            {{ if is_deleted }}
                <p>This comment was removed.</p>
            {{ else }}
                {{ comment }}
            {{ /if }}
        </div>
    </div>
{{ /meerkat:responses }}

However, we might just want to hide the comment completely if it doesn't have replies. We can do this by adding another conditional check:

{{ meerkat:responses show_hidden="true" }}
    {{ if is_deleted == false || is_deleted and has_replies }}
        <div class="media">
            <div class="media-body">
                <h4 class="media-heading">{{ name }}</h4>
                {{ if is_deleted }}
                    <p>This comment was removed.</p>
                {{ else }}
                    {{ comment }}
                {{ /if }}

                {{ if has_replies }}
                    {{ *recursive comments* }}
                {{ /if }}
            </div>
        </div>
    {{ /if }}
{{ /meerkat:responses }}