<p>You can use a <a href="https://craftcms.com/docs/4.x/routing.html#dynamic-routes" rel="nofollow noreferrer">custom route</a> for this. While sections only support one default URL for each entry, you can add additional routes related to entries, either through the backend (<em>Settings</em> -&gt; <em>Routes</em>) or in your <code>config/routes.php</code> file.</p>
<p>Add a route that looks like <code>blog/{slug}/comments</code> through the backend (you can also use the <a href="https://www.yiiframework.com/doc/guide/2.0/en/runtime-routing#named-parameters" rel="nofollow noreferrer">alternative syntax for named parameters</a>, see <a href="https://craftcms.com/docs/4.x/routing.html#advanced-routing-with-url-rules" rel="nofollow noreferrer">advanced routing</a>). Point the route directly to a template, or to a controller that renders the comments template.</p>
<p>Inside the template (or controller), you need to use an entry query to find the entry that is specified as part of the URL:</p>
<pre class="lang-twig prettyprint-override"><code>{% set entry = craft.entries()
    .section('blog')
    .slug(slug)
    .one()
%}
</code></pre>
<p>Keep in mind that visitors can enter any slug in the URL that will match the route, so this query may return <code>null</code>. In this case, you want to throw a 404 error to return a 404 response and display the appropriate <a href="https://craftcms.com/docs/4.x/routing.html#error-templates" rel="nofollow noreferrer">error page</a>:</p>
<pre class="lang-twig prettyprint-override"><code>{% if not entry %}
    {% exit 404 %}
{% endif %}
</code></pre>
<p>After this, you have the entry the page belongs to in the <code>entry</code> variable and can display its comments as well as the comment submission form.</p>

CC BY-SA 4.0
2023-01-23T11:08:51.773Z
2023-01-23T11:08:51.773Z
MoritzLost
<p>I really searched this forum for question like this but i was not able to find the answer.</p>
<p>Im creating news portal website, where I have blog entries with url like this
<code>/blog/SLUG</code></p>
<p>I want for every blog article to also have
<code>/blog/SLUG/comments</code>
where I will display some info from entry like title, postDate etc
but instead of regular content a I will display comment form.</p>
<p>Thanks in advance</p>

<templating><comments>
Create automatic subpage (kind of) for each entry
# Create automatic subpage (kind of) for each entry

(Asked by: username_0 on 2023-01-22)

I really searched this forum for question like this but i was not able to find the answer.

Im creating news portal website, where I have blog entries with url like this
`/blog/SLUG`

I want for every blog article to also have
`/blog/SLUG/comments`
where I will display some info from entry like title, postDate etc
but instead of regular content a I will display comment form.

Thanks in advance

**Tags:** templating, comments

---

## 1 answers

### Answer by username_1 on 2023-01-23. Score: 3 | Accepted answer

You can use a custom route for this. While sections only support one default URL for each entry, you can add additional routes related to entries, either through the backend (Settings -> Routes) or in your config/routes.php file.
Add a route that looks like blog/{slug}/comments through the backend (you can also use the alternative syntax for named parameters, see advanced routing). Point the route directly to a template, or to a controller that renders the comments template.
Inside the template (or controller), you need to use an entry query to find the entry that is specified as part of the URL:
{% set entry = craft.entries()
    .section('blog')
    .slug(slug)
    .one()
%}

Keep in mind that visitors can enter any slug in the URL that will match the route, so this query may return null. In this case, you want to throw a 404 error to return a 404 response and display the appropriate error page:
{% if not entry %}
    {% exit 404 %}
{% endif %}

After this, you have the entry the page belongs to in the entry variable and can display its comments as well as the comment submission form.


---

