Answers.Body: <p>Route: <code>{slug}-recipes</code></p>
  
  <p>The in the template:</p>
  
  <pre><code>{% set parts = craft.app.request.getSegment(1)|split("-") %}
  {% set newslug = parts[0] %}
  </code></pre>
  
  <p>Then you can use: <code>.slug(newslug)</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T21:50:30.907Z
Answers.Text: Just tried and getting following error - When using set, you must have the same number of variables and assignments.
Answers.UserDisplayName: Mark H.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T23:47:56.183Z
Answers.Text: Brad, your edit did the trick. I just changed this part |split("-") to |split("-recipes"). Thanks.
Answers.UserDisplayName: Mark H.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T13:56:36.197Z
Answers.LastActivityDate: 2020-03-25T22:48:08.183Z
Answers.LastEditDate: 2020-03-25T22:48:08.183Z
Answers.UserDisplayName: Jim Wyse
Answers.Body: <p>I never do this before, but maybe it works.</p>
  
  <pre><code>return [
    '&lt;value:{slug}&gt;-recipes' =&gt;  ['template' =&gt; '_recipes/restaurant'],
  ]
  </code></pre>
  
  <p>and you can get the value in a template like this :</p>
  
  <pre><code>{{value}}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T21:36:00.823Z
Answers.Text: Yes, this approach would work according to the routing docs but it will slow the things down since I can't specify exact channel with entries to look for.
Answers.UserDisplayName: Mark H.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T14:43:58.847Z
Answers.LastActivityDate: 2020-03-25T14:43:58.847Z
Answers.UserDisplayName: aodihis
Body: <p>I'm using the following code for now:</p>
  
  <pre><code>Route (in the control panel)
      recipes/{slug} loads _recipes/restaurant
  
  In the template to define the restaurant and list its items
      {% set restaurant = craft.entries.section('restaurants').slug(craft.app.request.getSegment(2)).one() %}
  </code></pre>
  
  <p>How do I change it to {slug}-recipes to make it work?</p>
  
  <p>Advanced routing (in routing file) is preferred for performance.</p>
  
  <p>Thanks.</p>
  
Tags: <routes><segments>
Title: Routing and Segments
ThreadText: # Routing and Segments
  
  (Asked by: username_0 on 2020-03-19)
  
  I'm using the following code for now:
  
  ```
  Route (in the control panel)
      recipes/{slug} loads _recipes/restaurant
  
  In the template to define the restaurant and list its items
      {% set restaurant = craft.entries.section('restaurants').slug(craft.app.request.getSegment(2)).one() %}
  
  ```
  
  How do I change it to {slug}-recipes to make it work?
  
  Advanced routing (in routing file) is preferred for performance.
  
  Thanks.
  
  **Tags:** routes, segments
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-03-25. Score: 1 | Accepted answer
  
  Route: `{slug}-recipes`
  
  The in the template:
  
  ```
  {% set parts = craft.app.request.getSegment(1)|split("-") %}
  {% set newslug = parts[0] %}
  
  ```
  
  Then you can use: `.slug(newslug)`
  
  > **Comments:**
  > **username_0**: Just tried and getting following error - When using set, you must have the same number of variables and assignments.  
  > **username_0**: Brad, your edit did the trick. I just changed this part |split("-") to |split("-recipes"). Thanks.  
  
  ---
  
  ### Answer by username_2 on 2020-03-25. Score: 1
  
  I never do this before, but maybe it works.
  
  ```
  return [
    '<value:{slug}>-recipes' =>  ['template' => '_recipes/restaurant'],
  ]
  
  ```
  
  and you can get the value in a template like this :
  
  ```
  {{value}}
  
  ```
  
  > **Comments:**
  > **username_0**: Yes, this approach would work according to the routing docs but it will slow the things down since I can't specify exact channel with entries to look for.  
  
  ---
  
  