Skip to main content

Breadcrumbs navigation for Dolmen applications.

Project description provides a breadcrumbs navigation for the Dolmen applications. It registers a viewlet to render the links.

Getting started

>>> from grokcore.component import testing

To test the breadcrumbs’ features, we need to create some content in an hypothetical application:

>>> from grokcore.content import Container
>>> from zope.component.hooks import getSite

>>> app = getSite()
>>> app['cave'] = Container()
>>> app['cave']['pot'] = Container()

To finish, we create a view. As we use a viewlet, we need a view to display something:

>>> import grokcore.view
>>> from zope.interface import Interface

>>> class simpleView(grokcore.view.View):
...   grokcore.view.context(Interface)
...   def render(self):
...     return u'For test purposes'

>>> testing.grok_component('simpleview', simpleView)


The component that allows to build URLs and Breadcrumbs is a multi adapter providing the IAbsoluteUrl interface. let’s have a closer look:

>>> from zope.component import getMultiAdapter
>>> from zope.publisher.browser import TestRequest
>>> from zope.traversing.browser.interfaces import IAbsoluteURL

>>> request = TestRequest()
>>> url = getMultiAdapter((app['cave'], request), IAbsoluteURL)

>>> url
< object at ...>

>>> from zope.interface.verify import verifyObject
>>> verifyObject(IAbsoluteURL, url)

>>> url()

>>> url.breadcrumbs()
({'url': '', 'name': ''},
 {'url': '', 'name': u'cave'})

The breadcrumbs uses the zope.dublincore interface, IDCDescriptiveProperties, in order to get the renderable title:

>>> from zope.dublincore.interfaces import IDCDescriptiveProperties
>>> adapter = IDCDescriptiveProperties(app['cave'])
>>> adapter.title


Now, we have some contents in our application. We can call our view and render the viewlet using its manager.

>>> from import master
>>> from import Breadcrumbs
>>> view = getMultiAdapter((app['cave'], request), name="simpleview")
>>> view
<simpleView object at ...>

The Breadcrumbs viewlet is registered for the manager:

>>> manager = master.Top(app['cave'], request, view)
>>> viewlet = Breadcrumbs(app['cave'], request, view, manager)
>>> viewlet
< object at ...>

Our contents have no title yet. If we render the viewlet, it uses the location in the parent (__name__):

>>> viewlet.update()
>>> print viewlet.render()
<div id="breadcrumb">
  <span class="you-are-here">You are here :</span>
  <span class="crumb">
    <a href="">cave</a>

If we set a title, it uses the title:

>>> adapter = IDCDescriptiveProperties(app['cave'])
>>> adapter.title = u'My cave with a fireplace'

>>> viewlet.update()
>>> print viewlet.render()
<div id="breadcrumb">
  <span class="you-are-here">You are here :</span>
  <span class="crumb">
    <a href="">My cave with a fireplace</a>

It works with all kind of objects, even if their metadata title is not set:

>>> app['cave']['pot']['bone'] = object()
>>> bone = app['cave']['pot']['bone']
>>> viewlet = Breadcrumbs(bone, request, view, manager)

>>> viewlet.update()
>>> print viewlet.render()
<div id="breadcrumb">
  <span class="you-are-here">You are here :</span>
  <span class="crumb">
    <a href="">My cave with a fireplace</a>
    <span class="breadcrumb-separator">&rarr;</span>
  <span class="crumb">
    <a href="">pot</a>
    <span class="breadcrumb-separator">&rarr;</span>
  <span class="crumb">
    <a href="">bone</a>

If the object is not locatable, we raise a TypeError:

>>> unlocatable = Container()
>>> viewlet = Breadcrumbs(unlocatable, request, view, manager)
>>> viewlet.update()
Traceback (most recent call last):
TypeError: There isn't enough context to get URL information. This is probably due to a bug in setting up location information.


1.0b2 (2011-01-18)

  • Added German translation.

1.0b1 (2010-07-08)

  • Tests no longer use IBaseContent from dolmen.content.

  • Added translations (French).

0.2 (2010-02-26)

  • The Breadcrumbs now uses an adaptation to the zope.dublincore IDCDescriptiveProperties interface in order to provide a name. The base multi adapter is registered for zope.location ILocation. Therefore, the Breadcrumbs is no longer limited to dolmen.content IBaseContent components.

  • The dependencies have been greatly cleaned. We are now using a Grok 1.1rc1 version of the ZTK. We no longer depend on packages.

  • Updated the IAbsoluteUrl component to match the changes in zope.traversing. The View has been removed and replace by a simple MultiAdapter providing IAbsoluteUrl.

0.1 (2009-11-08)

  • Initial release

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution (7.2 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page