Skip to content

How do I grab the current page's parent name? #7101

Answered by squidfunk
LizThompson93 asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks for the praise! I'm glad our work is useful to you ❤️

page.ancestors contains the list of ancestors in increasing levels, so page.ancestors[0] should be what you're looking for. Note that you should safe guard for the case when there are no ancestors, but something like the following should work, which means you should be able to integrate this into your footer.html override:

{% if page.ancestors %}
  {{ page.ancestors[0] }}
{% endif %}

Feel free to share your final solution, when you managed to work something out, so others can benefit as well ☺️

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@LizThompson93
Comment options

Answer selected by LizThompson93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants