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

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

<pre><code>{% if comment.isFlagged() == false %}
    ...
{% endif %}
{% ifchildren %}
    ...
{% endifchildren %}
{% if comment.isFlagged() == false %}
    ...
{% endif %}
</code></pre>

<p><strong>EDIT:</strong></p>

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

CC BY-SA 4.0
2019-11-05T07:18:42.520Z
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
CC BY-SA 4.0
2019-11-05T19:46:37.677Z
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
CC BY-SA 4.0
2019-11-04T23:11:07.397Z
2019-11-05T19:48:12.930Z
2019-11-05T19:48:12.930Z
Lindsey D
<p>Craft CMS V2. <br>
Comment Plugin: <a href="https://verbb.io/craft-plugins/comments" rel="nofollow noreferrer">verbb comment</a></p>

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

            {% ifchildren %}
                &lt;ul class="child"&gt;
                    {% children %}
                &lt;/ul&gt;
            {% endifchildren %}
          &lt;/li&gt;
       {% endif %}
    {% endnav %}
&lt;/ul&gt;
</code></pre>

<p>The above code creates this error:</p>

<pre><code>Unexpected "ifchildren" tag (expecting closing tag for the "if" tag)
</code></pre>

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

CC BY-SA 4.0
2019-11-06T10:40:32.503Z
Could something along those lines work - https://craftcms.stackexchange.com/questions/30688/show-only-children-relative-to-current-page/30695#30695 ?
Oli
<craft2><comments>
'If/else' statement inside 'nav' tag
# 'If/else' statement inside 'nav' tag

(Asked by: username_0 on 2019-11-04)

Craft CMS V2. 
Comment Plugin: verbb comment

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

            {% ifchildren %}
                
                    {% children %}
                
            {% endifchildren %}
          
       {% endif %}
    {% endnav %}


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.

**Tags:** craft2, comments

> **Comments:**
> **username_1**: Could something along those lines work - https://craftcms.stackexchange.com/questions/30688/show-only-children-relative-to-current-page/30695#30695 ?  

---

## 1 answers

### Answer by username_2 on 2019-11-04. Score: 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.

> **Comments:**
> **username_0**: 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.  
> **username_2**: 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.  

---

