I'm trying to set up a breadcrumb section in wagtail. Fortunately, there is a great example provided by Bake Demo which is simply a template tag which returns the list of ancestors of the current page.
@register.inclusion_tag('tags/breadcrumbs.html', takes_context=True)
def breadcrumbs(context):
self = context.get('self')
if self is None or self.depth <= 2:
# When on the home page, displaying breadcrumbs is irrelevant.
ancestors = ()
else:
ancestors = Page.objects.ancestor_of(
self, inclusive=True).filter(depth__gt=1)
return {
'ancestors': ancestors,
'request': context['request'],
}
The problem with this code is I need language support to display the links in the current language. Since my translation fields are located in the derived Page classes, I need to look up the corresponding translation.