ANN: plone.browserlayer - installable layers for view components that are visible after product install only
Martin Aspeli
optilude at gmx.net
Sun Sep 23 23:17:06 UTC 2007
Hi all,
A while ago, someone identified a hole in our view/viewlet/portlet
story. Whilst plone.theme gives us a way to override or register new
browser components (pages/views, viewlets, portlets, resources etc) for
a particular *theme* only, it was difficult for a third party product to
provide an "installable" browser component.
In Zope 3, most ZCML directives in the 'browser' namespace take a
'layer' option. For example:
<browser:page
name="foo"
for="*"
template="my-template.pt"
permission="zope.Public"
layer=".interfaces.IMyLayer"
/>
A layer is just an interface, which should be applied as a marker
interface to the request. The view @@foo above will only be available if
IMyLayer is applied to the request. plone.theme provides a way to
associated a layer (one-to-one) with a selected Theme (in portal_skins),
but it's obviously not feasible for each third-party product to have its
own theme (since only one can be active at once).
Enter plone.browserlayer. This lets you register a layer using
GenericSetup, i.e. during product installation. A traversal hook similar
to the one in plone.theme ensures that it's applied when you traverse
into the Plone site.
plone.browserlayer is not part of Plone core (yet), but works as a
standalone product. The only caveat is that you need to install it,
register its ZCML (e.g. with a slug or include) and install its
extension profile (to get the new import/export handlers). Then, you can
create a simple marker interface like:
from zope.interface import Interface
class IMyProductLayer(Interface):
"""Browser layer for this particular product
"""
Then add a browserlayer.xml file to your profile and do:
<layers>
<layer name="my.product"
interface="my.product.interfaces.IMyProductLayer" />
</layers>
Please see the README.txt file in the package for more[1].
plone.browserlayer 1.0b1 is in the Cheese Shop.
I'd like some feedback on this approach - I think it works pretty well,
but there may be other things I haven't thought about. I'd also really
appreciate a volunteer to write a quick how-to on this, to save me the
trouble. :-)
[1]
http://dev.plone.org/plone/browser/plone.browserlayer/trunk/plone/browserlayer/README.txt
--
Acquisition is a jealous mistress
More information about the Product-Developers
mailing list