breadcrumb design

207 views
Skip to first unread message

Richard

unread,
Jul 16, 2009, 8:45:38 PM7/16/09
to web2py Web Framework
hello,

Does anyone have a neat breadcrumb link system for web2py?
http://en.wikipedia.org/wiki/Breadcrumb_(navigation)

Currently each of my controller functions define a menu variable like
this:
breadcrumbs = [A('Browse', _href=URL(...)), A('Book', _href=URL(...)),
'View']
And then the base view uses this to generate the links.
However this creates a lot of redundancy for deep links.

I remember in Django they use inheritance chains to build up the
breadcrumbs to avoid this redundancy. Is there a way to do something
like that in web2py?

Richard

Alex Fanjul

unread,
Jul 16, 2009, 8:52:14 PM7/16/09
to web...@googlegroups.com
I agree with you Richard,
In deed, in statusbar there is already a "kind of breadcrumb" but
wihtout links...

A vote for this inbuild functionallity...
Otherwise, I bet that someone has a quick and simple idea to do this
with one function and getting the information from url app, controller,
function.

Alex F
--
Alejandro Fanjul Fdez.
alex....@gmail.com
www.mhproject.org

Alex Fanjul

unread,
Jul 21, 2009, 9:36:43 AM7/21/09
to web...@googlegroups.com
Any good pattern / shortcut to do this? (breadcrumbs)

thanks
alex f

El 17/07/2009 2:45, Richard escribió:

Richard

unread,
Aug 4, 2009, 8:48:47 PM8/4/09
to web2py-users
On Jul 17, 10:52 am, Alex Fanjul <alex.fan...@gmail.com> wrote:
> I agree with you Richard,
> In deed, in statusbar there is already a "kind of breadcrumb" but
> wihtout links...
>
> A vote for this inbuild functionallity...
> Otherwise, I bet that someone has a quick and simple idea to do this
> with one function and getting the information from url app, controller,
> function.

hmm, doing it automatically from the URL might work for me if I plan
it right.
Does anyone else already have their own breadcrumb system?

Richard

Richard

unread,
Aug 7, 2009, 3:34:34 AM8/7/09
to web2py-users
hi Alex,

I am now using this automatic breadcrumb function:


def breadcrumbs():
"Create breadcrumb links for current request"
# make links pretty by capitalizing and using 'home' instead of
'default'
pretty = lambda s: s.replace('default', 'home').replace('_', '
').capitalize()
menus = [A('Home', _href=URL(r=request, c='default', f='index'))]
if request.controller != 'default':
# add link to current controller
menus.append(A(pretty(request.controller), _href=URL
(r=request, c=request.controller, f='index')))
if request.function == 'index':
# are at root of controller
menus[-1] = pretty(request.controller)
else:
# are at function within controller
menus.append(pretty(request.function))
return XML(' > '.join(str(m) for m in menus))


Has anyone else got a system they can share?
Richard

Alexandre Andrade

unread,
Dec 28, 2009, 3:45:30 PM12/28/09
to web...@googlegroups.com
I improved the function and put it at http://www.web2pyslices.com/main/slices/take_slice/46

Features:

  • links in every breadcrumb
  • can set a breadcrumb to args
  • can localize/personalize the controllers - using T()

Thanks to Richard <richardbp(at)gmail.com>, for original function that I made improvements

Put in your model/module:

Select
    def breadcrumbs(arg_title=None):

"Create breadcrumb links for current request"
# make links pretty by capitalizing and using 'home' instead of 'default'
       #pretty = lambda s: s.replace('default', 'Início').replace('_', ' ').capitalize()
menus = [A(T('Home'), _href=URL(r=request, c='default', f='index'))]

if request.controller != 'default':
# add link to current controller
           menus.append(A(T(pretty(request.controller)), _href=URL(r=request, c=request.controller, f='index')))

if request.function == 'index':
# are at root of controller
               menus[-1] = A(T(pretty(request.controller)), _href=URL(r=request, c=request.controller, f=request.function))

else:
# are at function within controller
               menus.append(A(T(pretty(request.function)), _href=URL(r=request, c=request.controller, f=request.function)))
# you can set a title putting using breadcrumbs('My Detail Title')
if request.args and arg_title:
menus.append(A(T(arg_title)), _href=URL(r=request, c=request.controller, f=request.function,args=[request.args]))
else:
#menus.append(A(pretty(request.controller), _href=URL(r=request, c=request.controller, f='index')))

if request.function == 'index':
# are at root of controller
               #menus[-1] = pretty(request.controller)
pass
#menus.append(A(pretty(request.controller), _href=URL(r=request, c=request.controller, f=request.function)))

else:
# are at function within controller
               menus.append(A(T(pretty(request.function)), _href=URL(r=request, c=request.controller, f=request.function)))
# you can set a title putting using breadcrumbs('My Detail Title')
if request.args and arg_title:
menus.append(A(T(arg_title), _href=URL(r=request, f=request.function,args=[request.args])))


return XML(' > '.join(str(m) for m in menus))

To use, put in your view:

Select
 {{=breadcrumbs() }}

or

Select
  {{=breadcrumbs('My Title for request.args ') }}
------------------------------------------------------------
2009/8/7 Richard <rich...@gmail.com>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com
To unsubscribe from this group, send email to web2py+un...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---




--
Atenciosamente

--
=========================
Alexandre Andrade
Hipercenter.com

JorgeRpo

unread,
Dec 28, 2009, 4:28:39 PM12/28/09
to web2py-users

On Dec 28, 3:45 pm, Alexandre Andrade <alexandrema...@gmail.com>
wrote:


> I improved the function and put it athttp://www.web2pyslices.com/main/slices/take_slice/46
>
> Features:
>

>    - links in every breadcrumb
>    - can set a breadcrumb to args
>    - can localize/personalize the controllers - using T()

> 2009/8/7 Richard <richar...@gmail.com>

> > web2py+un...@googlegroups.com<web2py%2Bunsu...@googlegroups.com>


> > For more options, visit this group at
> >http://groups.google.com/group/web2py?hl=en
> > -~----------~----~----~----~------~----~------~--~---
>
> --
> Atenciosamente
>
> --
> =========================
> Alexandre Andrade
> Hipercenter.com

Hmmmm

You should make a little effort and create a menu plugin too. ;)

They have similarities with a breadcrumb ..

--
sig text

Alexandre Andrade

unread,
Dec 28, 2009, 5:24:38 PM12/28/09
to web...@googlegroups.com
I don't know the specs to do a plugin.

I posted a message yesterday about it but have no answers



2009/12/28 JorgeRpo <jorg...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.


Alexandre Andrade

unread,
Dec 28, 2009, 7:41:40 PM12/28/09
to web...@googlegroups.com
I think it is what you want:

http://www.web2pyslices.com/main/slices/take_slice/3

while it can be improved

2009/12/28 JorgeRpo <jorg...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.


Alex Fanjul

unread,
Dec 28, 2009, 8:07:29 PM12/28/09
to web...@googlegroups.com, Alexandre Andrade
I don't know if I have problems with my email (cause nobody responded me the last ones asking for help), anyway next try:
Thank you so much Alexandre, I think is a very useful bit of code because this feature (breadcumbs) its a must for web 2.0 nowdays, and from my point of view I think it should be included in web2py framework.
After trying to review and understand your code, the most impressive part (for a Java ex-programmer like me) its this little line: ***return XML(' > '.join(str(m) for m in menus))***

Alex F

--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

Richard

unread,
Dec 28, 2009, 9:59:12 PM12/28/09
to web2py-users
neat!


On Dec 29, 7:45 am, Alexandre Andrade <alexandrema...@gmail.com>


wrote:
> I improved the function and put it athttp://www.web2pyslices.com/main/slices/take_slice/46
>
> Features:
>
>    - links in every breadcrumb

>    - can set a breadcrumb to args
>    - can localize/personalize the controllers - using T()

> 2009/8/7 Richard <richar...@gmail.com>

> > web2py+un...@googlegroups.com<web2py%2Bunsu...@googlegroups.com>

Alexandre Andrade

unread,
Dec 29, 2009, 4:14:25 PM12/29/09
to web...@googlegroups.com
I make a new version, "Full Breadcrumb"  for applications that use nested functions, where you want the user pass by a function first to go to another, so you can set the parent functions, getting the history of navigation or hide the own function

http://www.web2pyslices.com/main/slices/take_slice/47

2009/12/29 Richard <rich...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/web2py?hl=en.


Alex Fanjul

unread,
Dec 29, 2009, 4:43:07 PM12/29/09
to web...@googlegroups.com, Alexandre Andrade
Sorry I don't understand you, could you put an example please?
Alex F
--
Reply all
Reply to author
Forward
0 new messages