Structure Nav: Output "Section" Title on both Landing and Decedents Hi all… I have a Structure organized like this:


Arts

Journals

Submissions

Books

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?
You can test for the entry's level property. Something like the following.

{% if entry.level == 1 %}
    &lt;h1&gt;{{ entry.title }}&lt;/h1&gt;
{% else %}
    &lt;h1&gt;{{ entry.ancestors.first.title }}&lt;/h1&gt;
{% endif %}