<p>One easy way to work around this is to use a query string instead of a segment. You'd redirect the user to for instance <code>/contact?receipt=thanks</code> instead of <code>/contact/thanks</code>, and you change the conditional in your template to something like this:</p>

<pre><code>{% if craft.request. getParam('receipt') == 'thanks' %}  
    ...thank you message
{% endif %}
</code></pre>

<p>I've always felt that this kind of information doesn't belong as a segment-part of an url, and the only reason we did that in EE was the lack of easy access to the query string.</p>

<p>Another way would be to set up a route like you did. Maybe set it to <code>(slug)/thanks</code>, where (slug) is the slug token. Then, at the beginning of your template, before trying to access entry, you check if it exists, and if it doesn't you pull it manually. Like this:</p>

<pre><code>{% if entry is not defined %}
    {% set entry = craft.entries({ slug: craft.request.segment(1) }).first() %}
{% endif %}
</code></pre>

<p>Hope one of those solutions helps.</p>

CC BY-SA 3.0
2014-09-11T17:25:33.833Z
Ah - thanks André. I think your solution re: the slug in the route and checking for the entry is a little cleaner - thanks.

And I understand your point re: the querystring - and maybe my 'thanks' example wasn't the best one. I know there are certainly instances where we'd want to leverage 'extra' url segments for some template logic and not rely on a querystring - for pages where SEO considerations came into play or other factors like easy of remembering a URL, etc.
Mike
CC BY-SA 3.0
2014-09-11T19:02:56.407Z
Ok, I see, I agree that in other cases it might make more sense to use a segment.
André Elvan
CC BY-SA 3.0
2014-09-11T16:34:30.210Z
2014-09-11T16:34:30.210Z
André Elvan
<p>I'm trying to make the jump from EE to Craft but struggling in this area (and thinking I may be approaching this all wrong).</p>

<p>In EE, I often use url segments (in combination with Freebie to ignore them) for certain logic in templates (ie. adding a last segment of 'thanks' to show a thank you message).</p>

<p>I cannot figure out how to do this well in Craft - or even if it is the right approach.</p>

<p>I have a channel entry with a slug of 'contact' and want to add 'thanks' to the url to conditionally display a thank you message on that page. I know I could add a route so that 'contact/thanks' will still load the correct template for that channel but I then run into the issue of that URL not matching the entry slug and no entry data is available for {{entry.whateverFields}}.</p>

<p>So then I did this to try to get around the issue by putting all my entry data in a for loop:</p>

<pre><code>{% for entry in craft.entries.section('standard').slug(craft.request.firstSegment) %}
    {{entry.title}}
    ...other template code in here
    {% if craft.request.lastSegment == 'thanks' %}  
        ...thank you message
    {% endif %}
{% endfor %}
</code></pre>

<p>This lets me now get the correct entry data loaded for this entry (or others in this section) and my thank you message still appears however it just feels like an awkward way to do it and I suspect in other scenarios it could become really messy.</p>

<p>Is there a better way to approach this in Craft?</p>

<p>Or can you actually have Craft ignore certain url segments?</p>

<templating><url><routing><craft-features><segments>
How to use url segments like with Freebie in EE
# How to use url segments like with Freebie in EE

(Asked by: username_0 on 2014-09-10)

I'm trying to make the jump from EE to Craft but struggling in this area (and thinking I may be approaching this all wrong).
In EE, I often use url segments (in combination with Freebie to ignore them) for certain logic in templates (ie. adding a last segment of 'thanks' to show a thank you message).
I cannot figure out how to do this well in Craft - or even if it is the right approach.
I have a channel entry with a slug of 'contact' and want to add 'thanks' to the url to conditionally display a thank you message on that page. I know I could add a route so that 'contact/thanks' will still load the correct template for that channel but I then run into the issue of that URL not matching the entry slug and no entry data is available for {{entry.whateverFields}}.
So then I did this to try to get around the issue by putting all my entry data in a for loop:
{% for entry in craft.entries.section('standard').slug(craft.request.firstSegment) %}
    {{entry.title}}
    ...other template code in here
    {% if craft.request.lastSegment == 'thanks' %}  
        ...thank you message
    {% endif %}
{% endfor %}

This lets me now get the correct entry data loaded for this entry (or others in this section) and my thank you message still appears however it just feels like an awkward way to do it and I suspect in other scenarios it could become really messy.
Is there a better way to approach this in Craft?
Or can you actually have Craft ignore certain url segments?

**Tags:** templating, url, routing, craft-features, segments


---

## 1 answers

### Answer by username_1 on 2014-09-11. Score: 4

One easy way to work around this is to use a query string instead of a segment. You'd redirect the user to for instance /contact?receipt=thanks instead of /contact/thanks, and you change the conditional in your template to something like this:
{% if craft.request. getParam('receipt') == 'thanks' %}  
    ...thank you message
{% endif %}

I've always felt that this kind of information doesn't belong as a segment-part of an url, and the only reason we did that in EE was the lack of easy access to the query string.
Another way would be to set up a route like you did. Maybe set it to (slug)/thanks, where (slug) is the slug token. Then, at the beginning of your template, before trying to access entry, you check if it exists, and if it doesn't you pull it manually. Like this:
{% if entry is not defined %}
    {% set entry = craft.entries({ slug: craft.request.segment(1) }).first() %}
{% endif %}

Hope one of those solutions helps.

> **Comments:**
> **username_0**: Ah - thanks André. I think your solution re: the slug in the route and checking for the entry is a little cleaner - thanks.  And I understand your point re: the querystring - and maybe my 'thanks' example wasn't the best one. I know there are certainly instances where we'd want to leverage 'extra' url segments for some template logic and not rely on a querystring - for pages where SEO considerations came into play or other factors like easy of remembering a URL, etc.  
> **username_1**: Ok, I see, I agree that in other cases it might make more sense to use a segment.  

---

