<p>It's probably your second-from-last line:</p>

<pre><code>{% endfor % }
</code></pre>

<p>should be:</p>

<pre><code>{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-08-05T13:06:34.787Z
Of course, you're right. Thank you very much!
MISC
CC BY-SA 3.0
2016-08-05T12:31:09.263Z
2016-08-05T12:31:09.263Z
Mike Pepper
<p>I have a comment section with comments and subcomments. A comment relates directly to the blog post while a subcomment relates to a comment.</p>

<p>Now, I have the following problem on the entry page: Showing the comments only is not a problem:</p>

<pre><code>{% for comment in craft.entries({
    section: comments,
    relatedTo: { targetElement: entry, field: "relentry" },
    order:     "sortOrder",
    limit:     null
}) %}
    &lt;p&gt;X&lt;/p&gt;
{% endfor %}
</code></pre>

<p>But when I insert the subcomments, I get the error message <code>Unexpected "}"</code>:</p>

<pre><code>{% for comment in craft.entries({
    section: comments,
    relatedTo: { targetElement: entry, field: "relentry" },
    order:     "sortOrder",
    limit:     null
}) %}
    &lt;p&gt;X&lt;/p&gt;
    {% for subcomment in craft.entries({
        section: comments,
        relatedTo: { targetElement: comment, field: "relentry" },
        order:     "sortOrder",
        limit:     null
    }) %}
        &lt;p&gt;Y&lt;/p&gt;
    {% endfor % }
{% endfor %}
</code></pre>

<p>Thank you very much for your help!</p>

<forloop><relatedto>
Error in case of nested for loops
# Error in case of nested for loops

(Asked by: username_0 on 2016-08-05)

I have a comment section with comments and subcomments. A comment relates directly to the blog post while a subcomment relates to a comment.
Now, I have the following problem on the entry page: Showing the comments only is not a problem:
{% for comment in craft.entries({
    section: comments,
    relatedTo: { targetElement: entry, field: "relentry" },
    order:     "sortOrder",
    limit:     null
}) %}
    X
{% endfor %}

But when I insert the subcomments, I get the error message Unexpected "}":
{% for comment in craft.entries({
    section: comments,
    relatedTo: { targetElement: entry, field: "relentry" },
    order:     "sortOrder",
    limit:     null
}) %}
    X
    {% for subcomment in craft.entries({
        section: comments,
        relatedTo: { targetElement: comment, field: "relentry" },
        order:     "sortOrder",
        limit:     null
    }) %}
        Y
    {% endfor % }
{% endfor %}

Thank you very much for your help!

**Tags:** forloop, relatedto


---

## 1 answers

### Answer by username_1 on 2016-08-05. Score: 2 | Accepted answer

It's probably your second-from-last line:
{% endfor % }

should be:
{% endfor %}

> **Comments:**
> **username_0**: Of course, you're right. Thank you very much!  

---

