Answers.Body: <p>You can test for the entry's <code>level</code> property. Something like the following.</p>
  
  <pre><code>{% if entry.level == 1 %}
      &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
  {% else %}
      &lt;h1&gt;{{ entry.ancestors.first.title }}&lt;/h1&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-12T19:44:04.867Z
Answers.Text: Ah, I didn't think about using level — that's a great solution. This is working, though I found that for the tertiary+ level we need "entry.ancestors.**first**.title" to get the right result … editing above.
Answers.UserDisplayName: philzelnar
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-12T19:51:11.073Z
Answers.Text: Great! I pulled this out of one of my own projects where the structure was limited to two levels. Couldn't remember whether '.first' or '.last' would get you to the top level. I updated the example to use 'first'.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-12T19:10:38.480Z
Answers.LastActivityDate: 2015-01-12T19:47:33.967Z
Answers.LastEditDate: 2015-01-12T19:47:33.967Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Hi all… I have a Structure organized like this:</p>
  
  <ol>
  <li>Arts
  <ul>
  <li>Journals
  <ul>
  <li>Submissions</li>
  </ul></li>
  <li>Books</li>
  </ul></li>
  <li>Sciences
  <ul>
  <li>Journals
  <ul>
  <li>Submissions</li>
  </ul></li>
  <li>Books</li>
  </ul></li>
  </ol>
  
  <p>…etc.</p>
  
  <p>In my template, I want to grab the "Section" (e.g. Arts, Sciences) that I'm in and output it at the top of the page, both on the main page and subpages.</p>
  
  <p>For decedents I can do that using:</p>
  
  <pre><code>    {% set currentSubject = entry.getAncestors().level(1) %}
      {% for entry in currentSubject %}
      {{ entry.title }}
      {% endfor %}
  </code></pre>
  
  <p>But if I'm on the main page (e.g. Arts, Sciences) itself getAncestors won't help. Is there a smart conditional that will give me the title of the top level page regardless of if I'm on it or a descendent of it?</p>
  
  <p>For some reason, I find myself hoping this can be done without looking at segments, but maybe that's the best route for this kind of thing?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-12T17:14:56.033Z
Comments.Text: I usually end up using segments for this, something like `{% set topLevel = craft.entries.slug(craft.request.segment(1)).first() %}`.
Comments.UserDisplayName: Steve Abraham
Tags: <structure>
Title: Structure Nav: Output "Section" Title on both Landing and Decedents
ThreadText: # Structure Nav: Output "Section" Title on both Landing and Decedents
  
  (Asked by: username_0 on 2015-01-12)
  
  Hi all… I have a Structure organized like this:
  
  1. Arts
     * Journals
       + Submissions
     * Books
  2. Sciences
     * Journals
       + Submissions
     * Books
  
  …etc.
  
  In my template, I want to grab the "Section" (e.g. Arts, Sciences) that I'm in and output it at the top of the page, both on the main page and subpages.
  
  For decedents I can do that using:
  
  ```
      {% set currentSubject = entry.getAncestors().level(1) %}
      {% for entry in currentSubject %}
      {{ entry.title }}
      {% endfor %}
  
  ```
  
  But if I'm on the main page (e.g. Arts, Sciences) itself getAncestors won't help. Is there a smart conditional that will give me the title of the top level page regardless of if I'm on it or a descendent of it?
  
  For some reason, I find myself hoping this can be done without looking at segments, but maybe that's the best route for this kind of thing?
  
  **Tags:** structure
  
  > **Comments:**
  > **username_1**: I usually end up using segments for this, something like `{% set topLevel = craft.entries.slug(craft.request.segment(1)).first() %}`.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-01-12. Score: 1 | Accepted answer
  
  You can test for the entry's `level` property. Something like the following.
  
  ```
  {% if entry.level == 1 %}
      <h1>{{ entry.title }}</h1>
  {% else %}
      <h1>{{ entry.ancestors.first.title }}</h1>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Ah, I didn't think about using level — that's a great solution. This is working, though I found that for the tertiary+ level we need "entry.ancestors.**first**.title" to get the right result … editing above.  
  > **username_2**: Great! I pulled this out of one of my own projects where the structure was limited to two levels. Couldn't remember whether '.first' or '.last' would get you to the top level. I updated the example to use 'first'.  
  
  ---
  
  