<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>

CC BY-SA 4.0
2020-03-25T21:50:30.907Z
Just tried and getting following error - When using set, you must have the same number of variables and assignments.
Mark H.
CC BY-SA 4.0
2020-03-25T23:47:56.183Z
Brad, your edit did the trick. I just changed this part |split("-") to |split("-recipes"). Thanks.
Mark H.
CC BY-SA 4.0
2020-03-25T13:56:36.197Z
2020-03-25T22:48:08.183Z
2020-03-25T22:48:08.183Z
Jim Wyse
<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>

CC BY-SA 4.0
2020-03-25T21:36:00.823Z
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.
Mark H.
CC BY-SA 4.0
2020-03-25T14:43:58.847Z
2020-03-25T14:43:58.847Z
aodihis
<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>

<routes><segments>
Routing and Segments
# 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 [
  '-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.  

---

