<p>Personally, I'd use segments for that. Something like:</p>

<pre><code>{% if craft.request.lastSegment == "page" %}
   do something
{% endif %}
</code></pre>

<p>or</p>

<pre><code>{% if craft.request.segments(1) == "page" %}
   do something
{% endif %}
</code></pre>

<p>These days, though, when not making a dynamic nav, I tend to pass a variable to my extended layouts or nav include. I find it much more flexible / robust than just relying on URL structures or segments.</p>

<p>In child template</p>

<pre><code>{% set currentNav = "home" %}
</code></pre>

<p>or</p>

<pre><code>{% include 'includes/_nav' with {'currentNav':'home'} %}
</code></pre>

<p>In include or extended layout</p>

<pre><code>{% if currentNav == "home" %}
   do something
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-09-02T01:22:23.103Z
That 2nd example should read segment, not segments...
Leah
CC BY-SA 3.0
2015-09-02T03:27:34.370Z
Hey Anna, not sure about this. Here is what the doc says: http://buildwithcraft.com/docs/templating/craft.request#segments
Jérôme Coupé
CC BY-SA 3.0
2015-09-03T00:46:45.393Z
Yeah I saw that. Not sure either - segmentS wasn't working for me, but segment was. Go figure :P
Leah
CC BY-SA 3.0
2014-10-30T06:49:42.030Z
2014-10-30T06:58:36.223Z
2014-10-30T06:58:36.223Z
Jérôme Coupé
<p>In addition to the options Jerome mentioned, you can also test for the Entry Type, which typically would be different for homepage vs blog, etc.</p>

<pre><code>{% if entry.type == 'home' %}
...
{% endif %}
</code></pre>

<p>Switch also works well here.</p>

<pre><code>{% switch entry.type %}
   {% case 'home' %}
   ...
   {% case 'blog' %}
   ...
   {% default %}
   ...
{% endswitch %}
</code></pre>

CC BY-SA 3.0
2014-10-30T07:35:55.070Z
2014-10-30T07:35:55.070Z
Douglas McDonald
<p>I am trying to simply change a <code>nav</code> element if one homepage and another if on the blog or another page.</p>

<p>I can the following to display if I set the following statement to <code>!=</code> </p>

<pre><code>{% if craft.request.getUrl() == 'http://testsite.com/page/' %}
    {{siteUrl}}
{% endif %}
</code></pre>

<p>However I can't figure out what that is returning as no matter what I put it doesn't work. </p>

CC BY-SA 3.0
2014-10-30T07:28:30.557Z
You can always see what a variable returns by outputting it like so {{ craft.request.getUrl() }}
naboovalley
<templating>
If url do something
# If url do something

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

I am trying to simply change a nav element if one homepage and another if on the blog or another page.
I can the following to display if I set the following statement to != 
{% if craft.request.getUrl() == 'http://testsite.com/page/' %}
    {{siteUrl}}
{% endif %}

However I can't figure out what that is returning as no matter what I put it doesn't work.

**Tags:** templating
> **Comments:**
> **username_1**: You can always see what a variable returns by outputting it like so {{ craft.request.getUrl() }}  

---

## 2 answers

### Answer by username_2 on 2014-10-30. Score: 10

Personally, I'd use segments for that. Something like:
{% if craft.request.lastSegment == "page" %}
   do something
{% endif %}

or
{% if craft.request.segments(1) == "page" %}
   do something
{% endif %}

These days, though, when not making a dynamic nav, I tend to pass a variable to my extended layouts or nav include. I find it much more flexible / robust than just relying on URL structures or segments.
In child template
{% set currentNav = "home" %}

or
{% include 'includes/_nav' with {'currentNav':'home'} %}

In include or extended layout
{% if currentNav == "home" %}
   do something
{% endif %}

> **Comments:**
> **username_3**: That 2nd example should read segment, not segments...  
> **username_2**: Hey Anna, not sure about this. Here is what the doc says: http://buildwithcraft.com/docs/templating/craft.request#segments  
> **username_3**: Yeah I saw that. Not sure either - segmentS wasn't working for me, but segment was. Go figure :P  

---

### Answer by username_4 on 2014-10-30. Score: 6

In addition to the options Jerome mentioned, you can also test for the Entry Type, which typically would be different for homepage vs blog, etc.
{% if entry.type == 'home' %}
...
{% endif %}

Switch also works well here.
{% switch entry.type %}
   {% case 'home' %}
   ...
   {% case 'blog' %}
   ...
   {% default %}
   ...
{% endswitch %}


---

