<p>I like the solution above. I'd add <code>craft.app.language</code> if you're working on a localized site.</p>

<pre><code>{% if craft.app.request.absoluteUrl == siteUrl or craft.app.request.absoluteUrl == siteUrl + craft.app.language %}
</code></pre>

CC BY-SA 4.0
2020-05-16T17:27:06.757Z
2020-05-16T17:35:55.080Z
2020-05-16T17:35:55.080Z
Leo Leoncio
<p>Both titles can not appear in your condition(on the homepage). Always only one <code>true</code> statement is executed.</p>

<p>To your problem: there is one <a href="https://craftcms.com/docs/templating/global-variables#siteUrl" rel="nofollow noreferrer">global variable</a> that solves your problem.</p>

<pre><code>{% if craft.request.getUrl() == siteUrl %}
    &lt;h2&gt;Homepage Title&lt;/h2&gt;
{% else %}
    &lt;h2&gt;Other Title&lt;/h2&gt;
{% endif %}
</code></pre>

<p>There is also the link <a href="https://craftcms.com/support/site-url" rel="nofollow noreferrer">How Craft Determines the Site URL</a>.</p>

CC BY-SA 3.0
2017-09-05T21:13:52.510Z
Thanks for this. The current solution you've suggested repeats `<h2>Homepage Title</h2>` twice on the homepage. Any ideas?
Sam
CC BY-SA 3.0
2017-09-05T21:17:55.767Z
Let me see the code and I may help you better.
Dominik Krulak
CC BY-SA 3.0
2017-09-05T21:28:29.360Z
The code from my question has been placed within an include (via root/_includes/feed.html). The include sits on the homepage like so `{% include "_includes/feed" %}`.
Sam
CC BY-SA 3.0
2017-09-05T22:01:54.860Z
Is only the code from question in your feed.html?
Dominik Krulak
CC BY-SA 3.0
2017-09-05T22:05:38.723Z
Have updated via my question :)
Sam
CC BY-SA 3.0
2017-09-05T22:11:21.513Z
It's odd. Your feed.html is fine. How is your homepage template build? Check your template for repeated the same code.
Dominik Krulak
CC BY-SA 3.0
2017-09-07T16:45:03.123Z
Mmmm, weird. I've included the homepage code in my question. Super simple and no repeating code...
Sam
CC BY-SA 3.0
2017-09-07T18:49:20.790Z
It must be a template related problem. I can't help you more unless I know how is whole homepage build and that includes what's in your templates. As you've mentioned in the question that both titles appear on the homepage. That means that Homepage Title showed even if first statement from the code was false. So you must have Homepage Title rendered twice for the homepage.
Dominik Krulak
CC BY-SA 3.0
2017-09-12T19:15:54.520Z
I feel so silly... the repeating title was coming from a text field via the homepage. Thanks for all your help. Your code works perfectly.
Sam
CC BY-SA 3.0
2017-09-12T19:29:41.813Z
Don't. It gives you a lesson. A lesson to know and understand your code. It makes life easier next time.
Dominik Krulak
CC BY-SA 4.0
2017-09-05T19:25:23.477Z
2018-12-12T08:23:30.270Z
2018-12-12T08:23:30.270Z
Dominik Krulak
<p>I have an {% include%} which displays entries from a structure. This {% include%} is displayed on the homepage and other entries throughout the site.</p>

<p>On the homepage, I'd like the include to show a specific title. On the other entries, I'd like it to show a different title.</p>

<p>Here's what I've tried:</p>

<pre><code>{% if craft.request.getUrl() == "/" %}
    &lt;h2&gt;Homepage Title&lt;/h2&gt;
{% else %}
    &lt;h2&gt;Other Title&lt;/h2&gt;
{% endif %}
</code></pre>

<p>Both titles appear on the homepage, but the <code>{% else %}</code> title appears correctly on the other entries. What am I doing wrong here?</p>

<p>Here's the code from the include file: </p>

<pre><code>&lt;div class="grid specialties"&gt;

    {% if craft.request.getUrl() == siteUrl %}
        &lt;h2&gt;Homepage Title&lt;/h2&gt;
    {% else %}
        &lt;h2&gt;Other Title&lt;/h2&gt;
    {% endif %}

    {% for entry in craft.entries.section('feed').find() %}
        &lt;article class="fifth"&gt;
            &lt;a href="{{ entry.url }}"&gt;
                {% set image = entry.icon.first() %}
                    &lt;img src="{{ image.url }}" alt="{{ image.title }}"&gt;
                {% endif %}
                &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
            &lt;/a&gt;
        &lt;/article&gt;
    {% endfor %}

&lt;/div&gt;
</code></pre>

<p>Here's the homepage code: </p>

<pre><code>{% extends "_layout" %}
{% block content %}
    {% include "_includes/layout_builder" %}
    {% include "_includes/specialties" %}
{% endblock %}
</code></pre>

<url><conditional><siteurl>
If page conditions
# If page conditions

(Asked by: username_0 on 2017-09-05)

I have an {% include%} which displays entries from a structure. This {% include%} is displayed on the homepage and other entries throughout the site.
On the homepage, I'd like the include to show a specific title. On the other entries, I'd like it to show a different title.
Here's what I've tried:
{% if craft.request.getUrl() == "/" %}
    Homepage Title
{% else %}
    Other Title
{% endif %}

Both titles appear on the homepage, but the {% else %} title appears correctly on the other entries. What am I doing wrong here?
Here's the code from the include file: 


    {% if craft.request.getUrl() == siteUrl %}
        Homepage Title
    {% else %}
        Other Title
    {% endif %}

    {% for entry in craft.entries.section('feed').find() %}
        
            
                {% set image = entry.icon.first() %}
                    
                {% endif %}
                {{ entry.title }}
            
        
    {% endfor %}



Here's the homepage code: 
{% extends "_layout" %}
{% block content %}
    {% include "_includes/layout_builder" %}
    {% include "_includes/specialties" %}
{% endblock %}

**Tags:** url, conditional, siteurl

---

## 2 answers

### Answer by username_2 on 2017-09-05. Score: 6 | Accepted answer

Both titles can not appear in your condition(on the homepage). Always only one true statement is executed.
To your problem: there is one global variable that solves your problem.
{% if craft.request.getUrl() == siteUrl %}
    Homepage Title
{% else %}
    Other Title
{% endif %}

There is also the link How Craft Determines the Site URL.

> **Comments:**
> **username_0**: Thanks for this. The current solution you've suggested repeats `<h2>Homepage Title</h2>` twice on the homepage. Any ideas?  
> **username_2**: Let me see the code and I may help you better.  
> **username_0**: The code from my question has been placed within an include (via root/_includes/feed.html). The include sits on the homepage like so `{% include "_includes/feed" %}`.  
> **username_2**: Is only the code from question in your feed.html?  
> **username_0**: Have updated via my question :)  
> **username_2**: It's odd. Your feed.html is fine. How is your homepage template build? Check your template for repeated the same code.  
> **username_0**: Mmmm, weird. I've included the homepage code in my question. Super simple and no repeating code...  
> **username_2**: It must be a template related problem. I can't help you more unless I know how is whole homepage build and that includes what's in your templates. As you've mentioned in the question that both titles appear on the homepage. That means that Homepage Title showed even if first statement from the code was false. So you must have Homepage Title rendered twice for the homepage.  
> **username_0**: I feel so silly... the repeating title was coming from a text field via the homepage. Thanks for all your help. Your code works perfectly.  
> **username_2**: Don't. It gives you a lesson. A lesson to know and understand your code. It makes life easier next time.  

---

### Answer by username_1 on 2020-05-16. Score: 2

I like the solution above. I'd add craft.app.language if you're working on a localized site.
{% if craft.app.request.absoluteUrl == siteUrl or craft.app.request.absoluteUrl == siteUrl + craft.app.language %}


---

