1

Craft CMS V2.
Comment Plugin: verbb comment

<ul>
    {% nav comment in comments %}
       {% if comment.isFlagged() == false %}
          <li>
              {% include '_forms/templates/comment-' ~ comment.status %}
              {% include '_forms/templates/form' %}

            {% ifchildren %}
                <ul class="child">
                    {% children %}
                </ul>
            {% endifchildren %}
          </li>
       {% endif %}
    {% endnav %}
</ul>

The above code creates this error:

Unexpected "ifchildren" tag (expecting closing tag for the "if" tag)

So, How can I use if/else condition inside the nav tag to hide flagged comment including it's children.

1

Short answer, it can't be done. I'm not sure why, but it's some sort of conflict with how nav, children, and ifchildren operates.

The workaround is ugly (but it works). Just use two separate, but identical if statements... one before the ifchildren, and one after.

{% if comment.isFlagged() == false %}
    ...
{% endif %}
{% ifchildren %}
    ...
{% endifchildren %}
{% if comment.isFlagged() == false %}
    ...
{% endif %}

EDIT:

If this solution doesn't work for you, I recommend looping over the comments array and removing all flagged comments before you run it through the nav loop.

| improve this answer | |
  • This solution is not appropriate in my case because approved child comments of flagged (inappropriate) parent comment shows though the parent flagged (inappropriate) comment has been removed. – johirpro Nov 5 '19 at 7:18
  • You could potentially repeat the same conditional again within the ifchildren tag. If that solution doesn't work for you, you might be out of luck. – Lindsey D Nov 5 '19 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.