<p>As @Robin Schambach said, you need to loop through the ancestors.</p>

<pre><code>{% set parent = craft.entries.section('pages').slug('phone-directory') %}
{% for ancestor in parent.getAncestors() %}
    {{ ancestor.title }}
{% endfor %}
</code></pre>

<p>This won't output the Phone Directory entry since you're just looping through its ancestors. So to complete the breadcrumbs you'll need to add 
<code>{{ parent.title }}</code> after the loop.</p>

CC BY-SA 4.0
2018-06-06T12:54:52.337Z
Thanks for this but I am still a little confused as to why this isn't working like I expect. I have updated my answer to hopefully explain better.
Terry Upton
CC BY-SA 4.0
2018-06-05T18:24:59.543Z
2018-06-05T18:24:59.543Z
Simon Kuran
<p>After much help and direction form @RobinSchambach (much appreciated). I have resolved this as follows;</p>

<pre><code>{% set currentPage = craft.entries.section('pages').slug('archive').first() %}
{% set currentAncestors = currentPage.getAncestors.find() %}
{% set crumbs = currentAncestors|merge([currentPage]) %}

{% if entry is defined and entry.section.handle != 'homepage' %}
{% set object = crumbs ?? entry.ancestors  %}
{% set crumbs =  object %}
{% set crumbDivider = '&lt;li&gt;&lt;span class="mx-3 text-grey text-xs"&gt;/&lt;/span&gt;&lt;/li&gt;' %}
&lt;nav class="mb-8 mx-6"&gt;
  &lt;ul class="list-reset flex flex-wrap items-center text-grey-dark text-sm"&gt;
    &lt;li class="mr-3 text-xs text-grey-light"&gt;You are in:&lt;/li&gt;
    &lt;li&gt;&lt;a href="{{ siteUrl }}"&gt;Home&lt;/a&gt;&lt;/li&gt;
    {% for crumb in crumbs %}
    {{ crumbDivider|raw }}
    &lt;li&gt;{{ crumb.getLink() }}&lt;/li&gt;
    {% endfor %}
    {{ crumbDivider|raw }}
    &lt;li class="text-grey-darker"&gt;{{ entry.title ?? category.title }}&lt;/li&gt;
  &lt;/ul&gt;
&lt;/nav&gt;
{% endif %}
</code></pre>

CC BY-SA 4.0
2018-06-06T14:45:31.510Z
2018-06-06T14:45:31.510Z
Terry Upton
<p>I have a a few pages outside of a structure but I want to display a breadcrumb for it as part of a structure. I am currently setting the parent page like so:
<code>{% set parent = craft.entries.section('pages').slug('phone-directory')</code> %}</p>

<p><code>{{ parent.ancestors }}</code></p>

<p>But when I loop through to get the ancestors it is only getting the current parent not all ancestors? Any idea how to achieve this?</p>

<p>The structure is<br>
Staff<br>
 &nbsp;&nbsp;&nbsp;&nbsp;Phone Directory</p>

<p>The reason I am trying to do this, is the 3rd level pages are either category pages or is a single with some specific routes. I want to manually set the real parent in the template, so I can get the ancestors for the breadcrumb trail as though it is part of the same section.</p>

<p>How can I manually set the parent entry in the template and get the ancestors from this entry?</p>

<p>**** <strong>UPDATED</strong> ****<br>
This is an update on the above to show my exact code and what isn't working and How I expect it work...If anyone ca shed some light?</p>

<p>So by default I am getting my breadcrumbs like so;</p>

<pre><code>{% if entry is defined and entry.section.handle != 'homepage' %}
{% set crumbs =  parent.ancetors ?? entry.ancestors|default([]) %}
{% set crumbDivider = '&lt;li&gt;&lt;span class="mx-3 text-grey text-xs"&gt;/&lt;/span&gt;&lt;/li&gt;' %}
&lt;nav class="mb-8 mx-6"&gt;
  &lt;ul class="list-reset flex flex-wrap items-center text-grey-dark text-sm"&gt;
    &lt;li class="mr-3 text-xs text-grey-light"&gt;You are in:&lt;/li&gt;
    &lt;li&gt;&lt;a href="{{ siteUrl }}"&gt;Home&lt;/a&gt;&lt;/li&gt;
    {% for crumb in crumbs %}
    {{ crumbDivider|raw }}
    &lt;li&gt;{{ crumb.getLink() }}&lt;/li&gt;
    {% endfor %}
    {{ crumbDivider|raw }}
    &lt;li class="text-grey-darker"&gt;{{ entry.title ?? category.title }}&lt;/li&gt;
  &lt;/ul&gt;
&lt;/nav&gt;
{% endif %}
</code></pre>

<p>This works as expect for normal standard entries. For example, within my Pages structure I have a parent of News with a Child of Internal News and on the Internal News page, the breadcrumb is reflected as;
<code>Home / News / SWH Internal News</code></p>

<p>Now on the news entry pages I want the breadcrumb to read as follows;
<code>Home / News / SWH Internal News / {{ Entry Title }}</code></p>

<p>I thought by setting the parent on the news/_entry.html template to the SWH Internal News page like so;
<code>{% set parent = craft.entries.section('pages').slug('archive') %}</code></p>

<p>Would then give me the ancestors of <code>News / SWH Internal News</code> but instead it only outputs SWH Internal News.</p>

CC BY-SA 4.0
2018-06-04T20:30:19.577Z
Can you add the breadcrumb loop code? It's hard to debug this without seeing the code that isn't working.
Simon Kuran
CC BY-SA 4.0
2018-06-05T06:56:51.407Z
even just using `{% set parent = craft.entries.section('pages').slug('phone-directory') %}`

`{{ parent.ancestors }}` only returns the one level though (Phone Directory). If I try {{ parent.first.ancestors }} I get the parent of the parent (Staff).  

The structure is:  
> Staff  
    >>Phone Directory and this is the entry I am setting.
  
I would expect this to then show the ancestors as Staff > Phone Directory
Terry Upton
CC BY-SA 4.0
2018-06-05T07:07:54.820Z
@TerryUpton You'll need to iterate the parents of course
Robin Schambach
<templating><parents>
Getting ancestors for manually set parent in template
# Getting ancestors for manually set parent in template

(Asked by: username_0 on 2018-06-04)

I have a a few pages outside of a structure but I want to display a breadcrumb for it as part of a structure. I am currently setting the parent page like so:
{% set parent = craft.entries.section('pages').slug('phone-directory') %}
{{ parent.ancestors }}
But when I loop through to get the ancestors it is only getting the current parent not all ancestors? Any idea how to achieve this?
The structure is
Staff
     Phone Directory
The reason I am trying to do this, is the 3rd level pages are either category pages or is a single with some specific routes. I want to manually set the real parent in the template, so I can get the ancestors for the breadcrumb trail as though it is part of the same section.
How can I manually set the parent entry in the template and get the ancestors from this entry?
**** UPDATED ****
This is an update on the above to show my exact code and what isn't working and How I expect it work...If anyone ca shed some light?
So by default I am getting my breadcrumbs like so;
{% if entry is defined and entry.section.handle != 'homepage' %}
{% set crumbs =  parent.ancetors ?? entry.ancestors|default([]) %}
{% set crumbDivider = '/' %}

  
    You are in:
    Home
    {% for crumb in crumbs %}
    {{ crumbDivider|raw }}
    {{ crumb.getLink() }}
    {% endfor %}
    {{ crumbDivider|raw }}
    {{ entry.title ?? category.title }}
  

{% endif %}

This works as expect for normal standard entries. For example, within my Pages structure I have a parent of News with a Child of Internal News and on the Internal News page, the breadcrumb is reflected as;
Home / News / SWH Internal News
Now on the news entry pages I want the breadcrumb to read as follows;
Home / News / SWH Internal News / {{ Entry Title }}
I thought by setting the parent on the news/_entry.html template to the SWH Internal News page like so;
{% set parent = craft.entries.section('pages').slug('archive') %}
Would then give me the ancestors of News / SWH Internal News but instead it only outputs SWH Internal News.

**Tags:** templating, parents
> **Comments:**
> **username_1**: Can you add the breadcrumb loop code? It's hard to debug this without seeing the code that isn't working.  
> **username_0**: even just using `{% set parent = craft.entries.section('pages').slug('phone-directory') %}`  `{{ parent.ancestors }}` only returns the one level though (Phone Directory). If I try {{ parent.first.ancestors }} I get the parent of the parent (Staff).    The structure is:   > Staff       >>Phone Directory and this is the entry I am setting.    I would expect this to then show the ancestors as Staff > Phone Directory  
> **username_2**: @TerryUpton You'll need to iterate the parents of course  

---

## 2 answers

### Answer by username_1 on 2018-06-05. Score: 2

As @Robin Schambach said, you need to loop through the ancestors.
{% set parent = craft.entries.section('pages').slug('phone-directory') %}
{% for ancestor in parent.getAncestors() %}
    {{ ancestor.title }}
{% endfor %}

This won't output the Phone Directory entry since you're just looping through its ancestors. So to complete the breadcrumbs you'll need to add 
{{ parent.title }} after the loop.

> **Comments:**
> **username_0**: Thanks for this but I am still a little confused as to why this isn't working like I expect. I have updated my answer to hopefully explain better.  

---

### Answer by username_0 on 2018-06-06. Score: 2

After much help and direction form @RobinSchambach (much appreciated). I have resolved this as follows;
{% set currentPage = craft.entries.section('pages').slug('archive').first() %}
{% set currentAncestors = currentPage.getAncestors.find() %}
{% set crumbs = currentAncestors|merge([currentPage]) %}

{% if entry is defined and entry.section.handle != 'homepage' %}
{% set object = crumbs ?? entry.ancestors  %}
{% set crumbs =  object %}
{% set crumbDivider = '/' %}

  
    You are in:
    Home
    {% for crumb in crumbs %}
    {{ crumbDivider|raw }}
    {{ crumb.getLink() }}
    {% endfor %}
    {{ crumbDivider|raw }}
    {{ entry.title ?? category.title }}
  

{% endif %}


---

