Answers.Body: <p>Set up a custom route in <code>config/routes.php</code> so that that URI points to your existing listing template:</p>
  
  <pre class="lang-php prettyprint-override"><code>return [
      'staff/&lt;route_staffMember&gt;/articles' =&gt; ['template' =&gt; '_listings/default'],
  ];
  </code></pre>
  
  <p>Then simply use the <code>relatedTo</code> parameter to alter which entries get listed. The template will have access to a variable called <code>route_staffMember</code> which you can use to fork logic between the filtered/non-filtered views. (I like to prefix these variables with <code>route_</code> because when I look at the code 6 months later I always scratch my head wondering where this magic variable is being set!)</p>
  
  <p>For example:</p>
  
  <pre><code>_listings/default
  
  {% set staffMemberId = route_staffMember is defined ? craft.entries.section('staff').slug(route_staffMember).ids() : null %}
  {% set entries = craft.entries.section('articles').relatedTo(staffMemberId).all() %}
  
  {# ...or, if you're using pagination: #}
  {% paginate craft.entries.section('articles').relatedTo(staffMemberId).limit(12) as pageInfo, entries %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-08T09:40:01.433Z
Answers.Text: Sorry, this is out of my brain range!  I have set it up as you suggest but I get 'template not found'.  I think I may be using the wrong method to link to the page?  On the individual article page I have a link that looks like this <a href="/staff/{{ staff.title|kebab }}/articles">See more articles by {{ staff.title }}</a>.   I'm setting the 'staff' variable with {% set staff = entry.linkArticleWithStaffMember.one() %}  where linkArticleWithStaffMember is an entries field.
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-08T13:15:42.093Z
Answers.Text: It should work ok... double-check your syntax. What is your template called that you want to route to? I named mine `_listings/default` - be sure to change that to whatever template you're using.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-06-05T17:18:53.853Z
Answers.LastActivityDate: 2020-06-05T17:18:53.853Z
Answers.UserDisplayName: James Smith
Body: <p>I have a Channel 'Articles' with an Entries field which is linked to entries in 'Staff Members' channel.  This is so that articles can be assigned to different members of staff.</p>
  
  <p>I have the generic listing (all articles) page working fine I just need to show the same page but filtered by a selected staff memeber. E.g. When viewing an individual article by a member of staff I would like to link to a page which only lists the articles assigned to that particular staff member.  This far would be ok but if possible I would also like to get the staff member name into the url... <a href="http://mysite/staff/joe-bloggs/articles" rel="nofollow noreferrer">http://mysite/staff/joe-bloggs/articles</a></p>
  
  <p>Any suggestions?</p>
  
  <p>Many thanks</p>
  
Tags: <filter><relatedto>
Title: Showing Entries based on an Entries Field but also showing a slug in the url
ThreadText: # Showing Entries based on an Entries Field but also showing a slug in the url
  
  (Asked by: username_0 on 2020-06-05)
  
  I have a Channel 'Articles' with an Entries field which is linked to entries in 'Staff Members' channel. This is so that articles can be assigned to different members of staff.
  
  I have the generic listing (all articles) page working fine I just need to show the same page but filtered by a selected staff memeber. E.g. When viewing an individual article by a member of staff I would like to link to a page which only lists the articles assigned to that particular staff member. This far would be ok but if possible I would also like to get the staff member name into the url... <http://mysite/staff/joe-bloggs/articles>
  
  Any suggestions?
  
  Many thanks
  
  **Tags:** filter, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-06-05. Score: 1
  
  Set up a custom route in `config/routes.php` so that that URI points to your existing listing template:
  
  ```php
  return [
      'staff/<route_staffMember>/articles' => ['template' => '_listings/default'],
  ];
  
  ```
  
  Then simply use the `relatedTo` parameter to alter which entries get listed. The template will have access to a variable called `route_staffMember` which you can use to fork logic between the filtered/non-filtered views. (I like to prefix these variables with `route_` because when I look at the code 6 months later I always scratch my head wondering where this magic variable is being set!)
  
  For example:
  
  ```
  _listings/default
  
  {% set staffMemberId = route_staffMember is defined ? craft.entries.section('staff').slug(route_staffMember).ids() : null %}
  {% set entries = craft.entries.section('articles').relatedTo(staffMemberId).all() %}
  
  {# ...or, if you're using pagination: #}
  {% paginate craft.entries.section('articles').relatedTo(staffMemberId).limit(12) as pageInfo, entries %}
  
  ```
  
  > **Comments:**
  > **username_0**: Sorry, this is out of my brain range!  I have set it up as you suggest but I get 'template not found'.  I think I may be using the wrong method to link to the page?  On the individual article page I have a link that looks like this <a href="/staff/{{ staff.title|kebab }}/articles">See more articles by {{ staff.title }}</a>.   I'm setting the 'staff' variable with {% set staff = entry.linkArticleWithStaffMember.one() %}  where linkArticleWithStaffMember is an entries field.  
  > **username_1**: It should work ok... double-check your syntax. What is your template called that you want to route to? I named mine `_listings/default` - be sure to change that to whatever template you're using.  
  
  ---
  
  