URL based breadcrumbs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@register.filter
def breadcrumbs(url):
    home = ['<li>you are here : <a href="/" title="Breadcrumb link to the homepage.">home</a> &raquo;</li>',]
    links = url.strip('/').split('/')
    bread = []
    total = len(links)-1
    for i, link in enumerate(links):
        if not link == '':
            bread.append(link)
            this_url = "/".join(bread)
            sub_link = re.sub('-', ' ', link)
            if not i == total:
                tlink = '<li><a href="/%s/" title="Breadcrumb link to %s">%s</a> &raquo;</li>' % (this_url, sub_link, sub_link)
            else:
                tlink = '<li>%s</li>' % sub_link
            home.append(tlink)
    bcrumb = "".join(home)
    return mark_safe(bcrumb)

More like this

  1. DaGood breadcrumbs by drozzy 5 years, 3 months ago
  2. Breadcrumbs for flatpages by jca 6 years, 4 months ago
  3. Breadcrumbs filter by Oggu 5 years, 3 months ago
  4. Template loader to target a specific template by miracle2k 2 years, 9 months ago
  5. Simple random file CAPTCHA by jeverling 2 years, 1 month ago

Comments

macmichael01 (on December 5, 2008):

You should at this in at line no. 7

if len(link) > 0 and link[0] == '?': break

so you don't append GET variables as a breadcrumb link.

#

macmichael01 (on December 5, 2008):

opps one other change, line no. 12:

if not i == total and not links[i+1][0] == '?':

That way it does not make a link out of the current location if there are GET variables in the url.

#

(Forgotten your password?)