<p>Basically the same as <a href="https://craftcms.stackexchange.com/a/6996/125">Steve suggested</a>, but I first merged the entries' IDs and then use them as a criteria in another <code>craft.entries</code> call:</p>

<pre><code>{% set landing = entry.getAncestors().level(1).first() %}

{% set landingId = landing.id %}
{% set ancestorIds = landing.getDescendants().ids() %}
{% set entryIds = [ landingId ]|merge( ancestorIds ) %}

{% set entries = craft.entries.id(entryIds) %}
</code></pre>

CC BY-SA 3.0
2015-02-05T16:37:56.647Z
This works. Nice one!
hamishtaplin
CC BY-SA 3.0
2015-02-05T16:32:05.117Z
2015-02-05T16:32:05.117Z
2017-04-13T12:51:00.200Z
carlcs
<p>Untested, but you should be able to do this by using the <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow">merge filter in Twig</a> to join the two results together.</p>

<p>Get the top level 'landing page' for this section:</p>

<pre><code>{% set landingPage = entry.getAncestors().level(1) %}
</code></pre>

<p>Get the descendants for this section:</p>

<pre><code>{% set childPages = entry.getAncestors().level(1).getDescendants() %}
</code></pre>

<p>Merge the two results together:</p>

<pre><code>{% set sectionPages = [ landingPage ]|merge(childPages) %}
</code></pre>

<p>Now create the navigation for the section using the sectionPages variable:</p>

<pre><code>&lt;nav&gt;
    &lt;ul&gt;
        {% nav page in sectionPages %}
            &lt;li&gt;
                {{ page.getLink() }}

                {% ifchildren %}
                    &lt;ul&gt;
                        {% children %}
                    &lt;/ul&gt;
                {% endifchildren %}
            &lt;/li&gt;
        {% endnav %}
    &lt;/ul&gt;
&lt;/nav&gt;
</code></pre>

CC BY-SA 3.0
2015-02-05T16:36:07.473Z
Thanks for answering! Merging throws an error "The merge filter only works with arrays or hashes; object and object given."
hamishtaplin
CC BY-SA 3.0
2015-02-05T16:41:28.983Z
Ah, OK - I did say it was untested! It looks like you'll need to follow [carlcs's answer](http://craftcms.stackexchange.com/a/6997/153) and get the IDs of the entries first.
Steve Rowling
CC BY-SA 3.0
2015-02-05T16:41:56.143Z
Just seen @carlcs edit to my answer - does that help?
Steve Rowling
CC BY-SA 3.0
2015-02-05T16:45:42.927Z
@Steve should work now, yep. Working with IDs first, allows you to use an ElementCriteriaModel (with pagination etc.), something you can't do with an array of EntryModels. But in this case it's actually not necessary and I like this (more simple) answer better. Performance should be about the same, I think.
carlcs
CC BY-SA 3.0
2015-02-06T08:59:36.307Z
I also prefer this answer, will mark this one instead.
hamishtaplin
CC BY-SA 3.0
2015-02-05T16:19:05.427Z
2015-02-05T16:39:05.857Z
2015-02-05T16:39:05.857Z
Steve Rowling
<p>There are several questions like this already but none seem to cover my use case. I have a structure that looks something like this:</p>

<pre><code>Landing Page 1
- Case Studies
-- Case Study 1
-- Case Study 2
-- Case Study 3
- Sub page
- Sub page
Landing Page 2
- Case Studies
-- Case Study 1
-- Case Study 2
-- Case Study 3
- Sub page
- Sub page
</code></pre>

<p>If I'm in any child of the 'Landing Pages' I want to create a nav (as per <a href="http://buildwithcraft.com/help/structure-nav" rel="nofollow">the docs</a>) but I cant' seem to get all of the pages I need. I can easily get the top level 'landing page': </p>

<pre><code>entry.getAncestors().level(1).first()
</code></pre>

<p>I can then get the descendants separately:</p>

<pre><code>entry.getAncestors().level(1).first().getDescendants()
</code></pre>

<p>However, I want a single ElementCriteriaModel with everything from the 'landing page' down in it.</p>

<p>Is this possible?</p>

<entries><navigation>
Building a nav from the top level page of a structure
# Building a nav from the top level page of a structure

(Asked by: username_0 on 2015-02-05)

There are several questions like this already but none seem to cover my use case. I have a structure that looks something like this:
Landing Page 1
- Case Studies
-- Case Study 1
-- Case Study 2
-- Case Study 3
- Sub page
- Sub page
Landing Page 2
- Case Studies
-- Case Study 1
-- Case Study 2
-- Case Study 3
- Sub page
- Sub page

If I'm in any child of the 'Landing Pages' I want to create a nav (as per the docs) but I cant' seem to get all of the pages I need. I can easily get the top level 'landing page': 
entry.getAncestors().level(1).first()

I can then get the descendants separately:
entry.getAncestors().level(1).first().getDescendants()

However, I want a single ElementCriteriaModel with everything from the 'landing page' down in it.
Is this possible?

**Tags:** entries, navigation

---

## 2 answers

### Answer by username_2 on 2015-02-05. Score: 4 | Accepted answer

Untested, but you should be able to do this by using the merge filter in Twig to join the two results together.
Get the top level 'landing page' for this section:
{% set landingPage = entry.getAncestors().level(1) %}

Get the descendants for this section:
{% set childPages = entry.getAncestors().level(1).getDescendants() %}

Merge the two results together:
{% set sectionPages = [ landingPage ]|merge(childPages) %}

Now create the navigation for the section using the sectionPages variable:

    
        {% nav page in sectionPages %}
            
                {{ page.getLink() }}

                {% ifchildren %}
                    
                        {% children %}
                    
                {% endifchildren %}
            
        {% endnav %}

> **Comments:**
> **username_0**: Thanks for answering! Merging throws an error "The merge filter only works with arrays or hashes; object and object given."  
> **username_2**: Ah, OK - I did say it was untested! It looks like you'll need to follow [carlcs's answer](http://craftcms.stackexchange.com/a/6997/153) and get the IDs of the entries first.  
> **username_2**: Just seen @carlcs edit to my answer - does that help?  
> **username_1**: @Steve should work now, yep. Working with IDs first, allows you to use an ElementCriteriaModel (with pagination etc.), something you can't do with an array of EntryModels. But in this case it's actually not necessary and I like this (more simple) answer better. Performance should be about the same, I think.  
> **username_0**: I also prefer this answer, will mark this one instead.  

---

### Answer by username_1 on 2015-02-05. Score: 4

Basically the same as Steve suggested, but I first merged the entries' IDs and then use them as a criteria in another craft.entries call:
{% set landing = entry.getAncestors().level(1).first() %}

{% set landingId = landing.id %}
{% set ancestorIds = landing.getDescendants().ids() %}
{% set entryIds = [ landingId ]|merge( ancestorIds ) %}

{% set entries = craft.entries.id(entryIds) %}

> **Comments:**
> **username_0**: This works. Nice one!  

---

