<p>Looks to me like there shouldn't be any quotes around <code>craft.app.request.getSegment(3)</code></p>

<p>Also I'd use <a href="https://docs.craftcms.com/v3/routing.html#accessing-named-parameters-in-your-templates" rel="nofollow noreferrer">named parameters</a> instead of .getSegment just seems a little bit more readable and robust.</p>

CC BY-SA 4.0
2019-03-27T07:32:11.740Z
2019-03-27T07:32:11.740Z
Udo
<p>I'm trying to create a submission page at the following URL structure</p>

<pre><code>/campaigns/this-is-a-test-creation/submissions
</code></pre>

<p>As you can see <code>/campaigns/</code> is the Channel and the <code>/this-is-a-test-creation/</code> is the entry slug. I'm trying to currently set up my page using routing and fetch the related entry, but I'm having difficulties.</p>

<p>My route in the CP is set up as follows and works.</p>

<p><code>/campaigns/{slug}/submissions</code></p>

<p>My code to fetch the relating entry doesn't</p>

<p><code>{% set entry = craft.entries.section('campaigns').slug('craft.app.request.getSegment(3)').one() %}
{{ entry.title }}
</code></p>

<p>This returns:</p>

<blockquote>
  <p>Impossible to access an attribute ("title") on a null variable.</p>
</blockquote>

<templating><routes>
Display Relating Entry based on Page Routing
# Display Relating Entry based on Page Routing

(Asked by: username_0 on 2019-03-27)

I'm trying to create a submission page at the following URL structure
/campaigns/this-is-a-test-creation/submissions

As you can see /campaigns/ is the Channel and the /this-is-a-test-creation/ is the entry slug. I'm trying to currently set up my page using routing and fetch the related entry, but I'm having difficulties.
My route in the CP is set up as follows and works.
/campaigns/{slug}/submissions
My code to fetch the relating entry doesn't
{% set entry = craft.entries.section('campaigns').slug('craft.app.request.getSegment(3)').one() %}
{{ entry.title }}

This returns:

Impossible to access an attribute ("title") on a null variable.

**Tags:** templating, routes


---

## 1 answers

### Answer by username_1 on 2019-03-27. Score: 2 | Accepted answer

Looks to me like there shouldn't be any quotes around `craft.app.request.getSegment(3)`

Also I'd use [named parameters](https://docs.craftcms.com/v3/routing.html#accessing-named-parameters-in-your-templates) instead of .getSegment just seems a little bit more readable and robust.


---

