Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Issues with crumb not appearing #57

Closed
KrunchMuffin opened this issue Nov 16, 2018 · 14 comments
Closed

Issues with crumb not appearing #57

KrunchMuffin opened this issue Nov 16, 2018 · 14 comments

Comments

@KrunchMuffin
Copy link

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
Copy link
Owner

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
Copy link
Author

Hey! Thanks for the quick reply!

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

@prymitive
Copy link
Owner

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

@KrunchMuffin
Copy link
Author

Thanks. I'll keep pluggin' away.

@KrunchMuffin
Copy link
Author

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
Copy link
Author

KrunchMuffin commented Nov 16, 2018

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
Copy link
Owner

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
Copy link
Owner

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
Copy link
Author

Ok, cool. thanks again.

@KrunchMuffin
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@prymitive
Copy link
Owner

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
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants