Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-16T17:27:06.757Z
Answers.LastActivityDate: 2020-05-16T17:35:55.080Z
Answers.LastEditDate: 2020-05-16T17:35:55.080Z
Answers.UserDisplayName: Leo Leoncio
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T21:13:52.510Z
Answers.Text: Thanks for this. The current solution you've suggested repeats `<h2>Homepage Title</h2>` twice on the homepage. Any ideas?
Answers.UserDisplayName: Sam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T21:17:55.767Z
Answers.Text: Let me see the code and I may help you better.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T21:28:29.360Z
Answers.Text: 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" %}`.
Answers.UserDisplayName: Sam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T22:01:54.860Z
Answers.Text: Is only the code from question in your feed.html?
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T22:05:38.723Z
Answers.Text: Have updated via my question :)
Answers.UserDisplayName: Sam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-05T22:11:21.513Z
Answers.Text: It's odd. Your feed.html is fine. How is your homepage template build? Check your template for repeated the same code.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-07T16:45:03.123Z
Answers.Text: Mmmm, weird. I've included the homepage code in my question. Super simple and no repeating code...
Answers.UserDisplayName: Sam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-07T18:49:20.790Z
Answers.Text: 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.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-12T19:15:54.520Z
Answers.Text: 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.
Answers.UserDisplayName: Sam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-12T19:29:41.813Z
Answers.Text: Don't. It gives you a lesson. A lesson to know and understand your code. It makes life easier next time.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-09-05T19:25:23.477Z
Answers.LastActivityDate: 2018-12-12T08:23:30.270Z
Answers.LastEditDate: 2018-12-12T08:23:30.270Z
Answers.UserDisplayName: Dominik Krulak
Body: <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>
  
Tags: <url><conditional><siteurl>
Title: If page conditions
ThreadText: # 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() == "/" %}
      <h2>Homepage Title</h2>
  {% else %}
      <h2>Other Title</h2>
  {% 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:
  
  ```
  <div class="grid specialties">
  
      {% if craft.request.getUrl() == siteUrl %}
          <h2>Homepage Title</h2>
      {% else %}
          <h2>Other Title</h2>
      {% endif %}
  
      {% for entry in craft.entries.section('feed').find() %}
          <article class="fifth">
              <a href="{{ entry.url }}">
                  {% set image = entry.icon.first() %}
                      <img src="{{ image.url }}" alt="{{ image.title }}">
                  {% endif %}
                  <h3>{{ entry.title }}</h3>
              </a>
          </article>
      {% endfor %}
  
  </div>
  
  ```
  
  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](https://craftcms.com/docs/templating/global-variables#siteUrl) that solves your problem.
  
  ```
  {% if craft.request.getUrl() == siteUrl %}
      <h2>Homepage Title</h2>
  {% else %}
      <h2>Other Title</h2>
  {% endif %}
  
  ```
  
  There is also the link [How Craft Determines the Site URL](https://craftcms.com/support/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 %}
  
  ```
  
  
  ---
  
  