breadcrumb solution

12 views
Skip to first unread message

Mike Dewhirst

unread,
Sep 9, 2009, 2:32:38 AM9/9/09
to django...@googlegroups.com
I would like to get breadcrumbs working in a simple way. Could anyone
please help?

I think I need a singleton with a dict like this ...

bread = singleton()

bread.dct['last_title'] =

Within each view and before doing anything else I want to ...

def someview(request):
title = 'whatever'
crumb = bread.dct['last_title']
bread.dct['last_title'] = title
# put title and crumb into the view context for extraction
# in the template as {{title}} and {{crumb}}


Is there a better way?

Thanks

Mike

Daniel Roseman

unread,
Sep 9, 2009, 5:02:45 AM9/9/09
to Django users
Why do you need a singleton here? This is a pattern you don't see
often in Python, so I'm intrigued as to why you think you need it.

Anyway, the better way is to do this as a templatetag.
--
DR.

Mike Dewhirst

unread,
Sep 9, 2009, 5:23:40 AM9/9/09
to django...@googlegroups.com
I'm obviously off track. I just looked at template tags again and can't
see anything - other than making a custom tag which seems a bit much for
me just at the moment.

Apart from hard-coding variables in a template and passing the values in
a context dictionary, how should it be done? Can you point me to any
examples?

Thanks

Mike




> --
> DR.
> >
>
>

David De La Harpe Golden

unread,
Sep 9, 2009, 6:46:35 AM9/9/09
to django...@googlegroups.com
Mike Dewhirst wrote:
> I would like to get breadcrumbs working in a simple way. Could anyone
> please help?

> Is there a better way?

One thing you can do is a "pure template" based breadcrumb
or pseudo-breadcrumb, assuming you have a template inheritance
graph with different views rendering different templates -
block.super is the key. I'm sure I picked this up in a blog post
somewhere, I didn't originate it:

*** base.html.djt:

<title>{% block title %}EXAMPLE{% endblock %}</title>
and

<div id="breadcrumbs">
{% block breadcrumb %}<a href="/">EXAMPLE</a>{% endblock %}
</div>


*** child.html.djt:

{% extends "base.html.djt" %}

{% block title %}{{ block.super }} :: CHILD{% endblock %}

{% block breadcrumb %}{{ block.super }} &raquo; <a href="{% url
proj.app.views.child %}">CHILD</a>{% endblock %}

*** grandchild.html.djt:

{% extends "child.html.djt" %}

{% block title %}{{ block.super }} :: GRANDCHILD{% endblock %}

{% block breadcrumb %}{{ block.super }} &raquo; <a href="{% url
proj.app.views.grandchild %}">GRANDCHILD</a>{% endblock %}

You get the idea.


Mike Dewhirst

unread,
Sep 9, 2009, 8:27:38 AM9/9/09
to django...@googlegroups.com
Thanks David - I do :)

Cheers

M
Reply all
Reply to author
Forward
0 new messages