prymitive / bootstrap-breadcrumbs

Django template tags for easy breadcrumbs using twitter bootstrap css classes or custom template
django-bootstrap-breadcrumbs.readthedocs.org
MIT License
93 stars 48 forks source link

Issues with crumb not appearing #57

Closed KrunchMuffin closed 5 years ago

KrunchMuffin commented 5 years ago

Full disclosure, I am a django/python newbie.

this is what I have

templates/base/base.html

...
<!-- Main content -->
<main class="main">

    <!-- Breadcrumb -->
    {% include 'base/breadcrumb.html' %}

    <!-- Page contents -->
    <div class="container-fluid">
        <div class="animated fadeIn">
            {% block content %}
            {% endblock %}
        </div>

    </div>
    <!-- /.conainer-fluid -->
</main>

...

templates/base/breadcrumb.html The initial "Dashboard" works.

{% load static %}
{% load django_bootstrap_breadcrumbs %}

{% block breadcrumbs %}
    {% breadcrumb "Dashboard" "/dashboard" %}
{% endblock %}

{% block breadcrumb %}
    {% render_breadcrumbs %}
{% endblock %}

templates/accounts/index.html

{% extends 'base/base.html' %}
{% load static %}
{% load django_bootstrap_breadcrumbs %}
{% block breadcrumbs %}
    {{ block.super }}
    {% breadcrumb "Account List" "account-list" %}
{% endblock %}
{% load common_extras %}
{% block content %}

All I end up with is Dashboard. I have tried different configurations. There are no errors. Django 2.1.2 Python 3.7

prymitive commented 5 years ago

It's been a while since I wrote any django code but I'm sure we can crack it together. I think it's because {% render_breadcrumbs %} is called to early. I would try moving it out of templates/base/breadcrumb.html and into templates/base/base.html or maybe even templates/accounts/index.html to see if that helps. That's the only quick tip I have right now, let me know if that still doesn't work.

KrunchMuffin commented 5 years ago

Hey! Thanks for the quick reply!

I tried it in different places with same result. So confused.

prymitive commented 5 years ago

🤔 I'll look into this over weekend, should be easy to reproduce

KrunchMuffin commented 5 years ago

Thanks. I'll keep pluggin' away.

KrunchMuffin commented 5 years ago

I think I got it! I took all the breadcrumb.html code and replaced the include inside base.html with it and it worked. So I guess there is an issue with includes?

KrunchMuffin commented 5 years ago

I have a question while I have you. In paths where I have an ID ie. 159, would it be possible to replace that with the actual company name it represents and use it in the breadcrumb? So...

From path /accountmgmt/154/detail/ Dashboard / Accounts / ACME Inc. / Detail

prymitive commented 5 years ago

I think that if you only got Dashboard than it's an ordering issue (rendering breadcrumbs list before it was fully populated), so it might be related to the way inheritance chain is setup.

prymitive commented 5 years ago

I have a question while I have you. In paths where I have an ID ie. 159, would it be possible to replace that with the actual company name it represents and use it in the breadcrumb? So...

Dashboard / Accounts / ACME Inc. / Detail

If you are using Django models than you can define str() and pass model instance as $label argument (docs) or pass any model attribute there as $label

KrunchMuffin commented 5 years ago

Ok, cool. thanks again.

KrunchMuffin commented 5 years ago

Hey again.

Having a small issue I can't figure out.

I get this far

image

But when I select a user to view detail on, I lose the company name

image

Goes like this...

Dashboard: (base.html) {% breadcrumb "Dashboard" "/dashboard" %}

Account List: (index.html) {% extends 'base/base.html' %} {% breadcrumb "Account List" "accountmgmt:account-list" %}

Martin's Cafe: (detail.html) {% extends 'accounts/index.html' %} {% breadcrumb detail.company_name|title "accountmgmt:account-detail" detail.profile_id %}

User List: (userlist.html) {% extends 'accounts/index.html' %} {% breadcrumb company_name|title "accountmgmt:account-detail" pid %} {% breadcrumb "User List" "accountmgmt:user-list" pid %}

Big Boss: (userdetail.html) {% extends 'accounts/userlist.html' %} {% breadcrumb detail.fullname|title "accountmgmt:user-detail" detail.user_id %}

prymitive commented 5 years ago

Is the detail object the user or the company? Does that one object have all those attributes you use? (company_name, profile_id, user_id)

KrunchMuffin commented 5 years ago

hmmm...not likely. it would have company and profile but not user

prymitive commented 5 years ago

Doesn't this mean that detail object used when you render those breadcrumbs can't render all of those, since for some breadcrumbs it needs to be a user but for others it's a company? I mean - when you render user page detail object is an user object, so when partial for rendering company title gets that passed it can't find company_name on it. I would recommend using more meaningful object names so it's obvious what you need to pass.

KrunchMuffin commented 5 years ago

Finally figured it out. Did a select_related for the account.