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

1 Answer 1

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.

2
  • 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, 2019 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, 2019 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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