<p>Variables like <code>entry</code> are only auto-injected for routes that match the Section's <strong>Site Settings</strong> routes:</p>

<p><a href="https://i.sstatic.net/Qod0t.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Qod0t.png" alt="enter image description here"></a></p>

<p>If you're using custom routes, they won't match, and you'll need to set <code>entry</code> (or whatever) yourself manually. SEOmatic uses the same Craft mechanism for recognizing injected <code>entry</code>s (or whatever), so the same applies there. Vide: <a href="https://nystudio107.com/blog/tips-for-using-seomatic-effectively#rendering-metadata-from-another-route" rel="nofollow noreferrer">Rendering Metadata From Another Route</a></p>

CC BY-SA 4.0
2019-11-18T16:09:13.317Z
Andrew - perfect. Thank you. Of course I should've checked your blog before posting here.
CreateSean
CC BY-SA 4.0
2019-11-17T23:47:54.823Z
2019-11-17T23:47:54.823Z
andrew.welch
<p>I've got a blog listing channel set up where I'm trying to filter entries listed by the entries field <code>blogAuthors</code> based on url segment.</p>

<p><code>/articles-and-excerpts/</code> loads the blog fine</p>

<p>added a route</p>

<p><a href="https://i.sstatic.net/Myn3j.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Myn3j.jpg" alt="enter image description here"></a></p>

<p>but when I go to a page like this <code>/articles-and-excperts/author/john-doe</code> I see errors until I add this to the template</p>

<pre><code>{% if entry is not defined %}
    {% set entry = craft.entries.section('blogListing').one() %}
{% endif %}
</code></pre>

<p>Then it works correctly. Why doesn't Craft recognize that this is the blogListing channel?</p>

<p>Also even though this works and displays the content SEOmatic doesn't recognize it now either.</p>

<p>Ultimately I need the following to load on this template:</p>

<p><code>/articles-and-excerpts/</code>
<code>/articles-and-excerpts/author/author.slug</code>
<code>/articles-and-excerpts/category/category.slug</code>
<code>/articles-and-excerpts/category/category.slug/author/author.slug</code></p>

<p>Currently I have categories using a separate template but haven't attempted to add in the author filtering.</p>

<p>Is there a better approach to this? I had started trying to combine url segments and a query string, but got stuck there as well <a href="https://craftcms.stackexchange.com/questions/33006/filtering-entries-by-category-and-author-channel">Filtering entries by category and author channel</a></p>

<templating><routes><category><plugin-seomatic>
Set Up Route to Template - then variable Entry is undefined
# Set Up Route to Template - then variable Entry is undefined

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

I've got a blog listing channel set up where I'm trying to filter entries listed by the entries field blogAuthors based on url segment.
/articles-and-excerpts/ loads the blog fine
added a route

but when I go to a page like this /articles-and-excperts/author/john-doe I see errors until I add this to the template
{% if entry is not defined %}
    {% set entry = craft.entries.section('blogListing').one() %}
{% endif %}

Then it works correctly. Why doesn't Craft recognize that this is the blogListing channel?
Also even though this works and displays the content SEOmatic doesn't recognize it now either.
Ultimately I need the following to load on this template:
/articles-and-excerpts/
/articles-and-excerpts/author/author.slug
/articles-and-excerpts/category/category.slug
/articles-and-excerpts/category/category.slug/author/author.slug
Currently I have categories using a separate template but haven't attempted to add in the author filtering.
Is there a better approach to this? I had started trying to combine url segments and a query string, but got stuck there as well Filtering entries by category and author channel

**Tags:** templating, routes, category, plugin-seomatic

---

## 1 answers

### Answer by username_1 on 2019-11-17. Score: 2 | Accepted answer

Variables like `entry` are only auto-injected for routes that match the Section's **Site Settings** routes:

[![enter image description here](https://i.sstatic.net/Qod0t.png)](https://i.sstatic.net/Qod0t.png)

If you're using custom routes, they won't match, and you'll need to set `entry` (or whatever) yourself manually. SEOmatic uses the same Craft mechanism for recognizing injected `entry`s (or whatever), so the same applies there. Vide: [Rendering Metadata From Another Route](https://nystudio107.com/blog/tips-for-using-seomatic-effectively#rendering-metadata-from-another-route)

> **Comments:**
> **username_0**: Andrew - perfect. Thank you. Of course I should've checked your blog before posting here.  

---

