mark last breadcrumb active

This commit is contained in:
Jakob Ketterl 2021-04-18 19:25:29 +02:00
parent 52b535c608
commit 77de488521

View File

@ -7,9 +7,9 @@ class BreadcrumbItem(object):
self.title = title self.title = title
self.href = href self.href = href
def render(self, documentRoot): def render(self, documentRoot, active=False):
return '<li class="breadcrumb-item"><a href="{documentRoot}{href}">{title}</a></li>'.format( return '<li class="breadcrumb-item {active}"><a href="{documentRoot}{href}">{title}</a></li>'.format(
documentRoot=documentRoot, href=self.href, title=self.title documentRoot=documentRoot, href=self.href, title=self.title, active="active" if active else ""
) )
@ -21,9 +21,11 @@ class Breadcrumb(object):
return """ return """
<ol class="breadcrumb"> <ol class="breadcrumb">
{crumbs} {crumbs}
{last_crumb}
</ol> </ol>
""".format( """.format(
crumbs="".join(item.render(documentRoot) for item in self.items) crumbs="".join(item.render(documentRoot) for item in self.items[:-1]),
last_crumb="".join(item.render(documentRoot, True) for item in self.items[-1:]),
) )
def append(self, crumb: BreadcrumbItem): def append(self, crumb: BreadcrumbItem):