Skip to content

Instantly share code, notes, and snippets.

@softquantum
Created June 24, 2024 02:16
Show Gist options
  • Save softquantum/bb4c412e2d45fe690271de81f53100ee to your computer and use it in GitHub Desktop.
Save softquantum/bb4c412e2d45fe690271de81f53100ee to your computer and use it in GitHub Desktop.
Django Template Tag for Breadcrumbs
@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, locale=Locale.get_active())
return {
"ancestors": ancestors,
"request": context["request"],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment