How can I get the parent page title in craft using twig?

2.9k Views Asked by At

Example I have a structure For all the subpages / child pages in the structure.

I want to access the title of its parent.

The result being that all the level 1 headers have the parent page title displayed as the header

All the children pages have the level 1 (parent page title) as the header

At the moment I am referencing entry.title

1

There are 1 best solutions below

0
On

You can access the parent in a struct via entry.parent in twig. For example:

{% if entry.parent %} 
  <h1>
    {{ entry.parent.title }}:<br>
    <small>{{ entry.title }}</small>
  </h1>
{% else %}
  <h1>{{  entry.title }}</h1>
{% endif %}