1

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.

1 Answers1

1

I think I've found the solution to this one: to get my custom Page object i need to add 'specific' method by changing this line:

ancestors = Page.objects.ancestor_of(self, inclusive=True).specific().filter(depth__gt=1)

Now I can use my own custom field in the template. something like this {{ancestors.custom_field}}