Skip to content

Instantly share code, notes, and snippets.

@mmmcorpsvit
Created July 31, 2021 11:19
Show Gist options
  • Save mmmcorpsvit/87db488b24cb96f87d35b43eea9e2dc4 to your computer and use it in GitHub Desktop.
Save mmmcorpsvit/87db488b24cb96f87d35b43eea9e2dc4 to your computer and use it in GitHub Desktop.
Django HTML snippest simple breadcrumb (one level, adapted for Bootstrap 5)
{#Example of use:#}
{#def render_my_page(request, mark_id)#}
{# context = {#}
{# 'breadcrumb': [ # This it!#}
{# ("Все Марки:", reverse('cars')), # with url#}
{# (f"Марка: {data['name']}",) # simple text#}
{# ],#}
{# 'id': mark_id, # custom id#}
{# }#}
{# return render(request, 'pages/my_page.html', context=context)#}
{% if breadcrumb %}
{# https://getbootstrap.com/docs/5.0/components/breadcrumb/#}
<nav style="--bs-breadcrumb-divider: '>'; padding-left: 15px;" aria-label="breadcrumb">
<ol class="breadcrumb">
{% for item in breadcrumb %}
{% if forloop.last %}
<li class="breadcrumb-item bg-primary active" aria-current="page">
{% else %}
<li class="breadcrumb-item bg-primary">
{% endif %}
{% if item.1 %}
<a href="{{ item.1 }}">{{ item.0 }}</a>
{% else %}
{{ item.0 }}
{% endif %}
</li>
{% endfor %}
</ol>
</nav>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment