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 = '<li><span class="mx-3 text-grey text-xs">/</span></li>' %}
<nav class="mb-8 mx-6">
<ul class="list-reset flex flex-wrap items-center text-grey-dark text-sm">
<li class="mr-3 text-xs text-grey-light">You are in:</li>
<li><a href="{{ siteUrl }}">Home</a></li>
{% for crumb in crumbs %}
{{ crumbDivider|raw }}
<li>{{ crumb.getLink() }}</li>
{% endfor %}
{{ crumbDivider|raw }}
<li class="text-grey-darker">{{ entry.title ?? category.title }}</li>
</ul>
</nav>
{% 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.
{% 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 Jun 5 '18 at 6:56