<p>Assuming that a <strong>Single</strong> is the right thing to use here (<em>and I'm not sold on that but I trust your judment</em>) the following is what I would do to accomplish what you want.</p>

<pre><code>// config/routes.php
'offers/listing/(?P&lt;entryId&gt;\d)' =&gt; 'listing/make-offer'

// templates/listing/make-offer.twig
{% set entry = entry is defined ? entry : craft.entries.id(entryId) %}
</code></pre>

<p><strong>Explanation</strong></p>

<p>First, we create an <a href="https://craftcms.com/docs/routing#advanced-routing" rel="nofollow noreferrer" title="Advanced Route">Advanced Route</a> to make the (single) <code>entryId</code> available to the template that will be loaded when the route matches.</p>

<p>Then, in the template, we set the <code>entry</code> variable to either the <code>entry</code> that Craft makes available to the template via its own routing or we fetch one explicitly by using the <code>entryId</code> passed to the template from the custom route. <em>Our route may take precedence over default routing, so the <code>entry is defined</code> check may be removed and rely instead on <code>craft.entries.id(entryId)</code></em></p>

<p><strong>End Result</strong></p>

<p>You should be able to navigate to <code>/offers/listing/1234</code>, which will load the <code>templates/listing/make-offer.twig</code> template with the <code>entryId</code> set to <code>1234</code>.</p>

<p>Hope this helps, feel free to follow up if something isn't clear.</p>

CC BY-SA 3.0
2017-04-01T17:47:06.657Z
Thank you! This makes perfect sense - I'm still getting a 404 though. Is it possible Craft is still reading the uri segment set in the section? It's a required field, so I'm not sure how to override it.
Damon
CC BY-SA 3.0
2017-04-01T18:09:56.263Z
May need to update the single to use a fixed URI rather than slug?!
Selvin Ortiz
CC BY-SA 3.0
2017-04-01T16:02:42.753Z
2017-04-01T16:02:42.753Z
Selvin Ortiz
<p>I am trying to have a dynamic uri segment for a single. I have this uri in the CP settings: </p>

<pre><code>offers/listing/{slug}
</code></pre>

<p>Where <code>{slug}</code> is the entryId. For example, <code>offers/listing/1234</code> </p>

<p>I have a template at <code>templates/listing/make-offer.twig</code></p>

<p>For the template path i have: <code>listing/make-offer</code></p>

<p>If I navigate to <code>site.com/offers/listing/1234</code> I get a 404.</p>

<p>However, if I make a custom route: </p>

<pre><code>URI looks like: offers/listing/(slug)
Loads template: listing/make-offer
</code></pre>

<p>Everything works. The downside is I would like to control the content on the top of the page through the CP.</p>

<p>I realize, this is something more of a channel (which I still get a 404), but this page will never go anywhere. It's a content page at the top with a contact form at the bottom.</p>

<p>Thank you for any suggestions!</p>

<templating><routes>
How can I have a dynamic uri segment for a single?
# How can I have a dynamic uri segment for a single?

(Asked by: username_0 on 2017-04-01)

I am trying to have a dynamic uri segment for a single. I have this uri in the CP settings: 
offers/listing/{slug}

Where {slug} is the entryId. For example, offers/listing/1234 
I have a template at templates/listing/make-offer.twig
For the template path i have: listing/make-offer
If I navigate to site.com/offers/listing/1234 I get a 404.
However, if I make a custom route: 
URI looks like: offers/listing/(slug)
Loads template: listing/make-offer

Everything works. The downside is I would like to control the content on the top of the page through the CP.
I realize, this is something more of a channel (which I still get a 404), but this page will never go anywhere. It's a content page at the top with a contact form at the bottom.
Thank you for any suggestions!

**Tags:** templating, routes

---

## 1 answers

### Answer by username_1 on 2017-04-01. Score: 2

Assuming that a Single is the right thing to use here (and I'm not sold on that but I trust your judment) the following is what I would do to accomplish what you want.
// config/routes.php
'offers/listing/(?P\d)' => 'listing/make-offer'

// templates/listing/make-offer.twig
{% set entry = entry is defined ? entry : craft.entries.id(entryId) %}

Explanation
First, we create an Advanced Route to make the (single) entryId available to the template that will be loaded when the route matches.
Then, in the template, we set the entry variable to either the entry that Craft makes available to the template via its own routing or we fetch one explicitly by using the entryId passed to the template from the custom route. Our route may take precedence over default routing, so the entry is defined check may be removed and rely instead on craft.entries.id(entryId)
End Result
You should be able to navigate to /offers/listing/1234, which will load the templates/listing/make-offer.twig template with the entryId set to 1234.
Hope this helps, feel free to follow up if something isn't clear.

> **Comments:**
> **username_0**: Thank you! This makes perfect sense - I'm still getting a 404 though. Is it possible Craft is still reading the uri segment set in the section? It's a required field, so I'm not sure how to override it.  
> **username_1**: May need to update the single to use a fixed URI rather than slug?!  

---

