Fun with Browserlayers in Diazo-Themed Plone Sites
Plone is a great CMS and with Diazo these days its really easy to theme a site. The headache we always had with theming all the past years is history.
Nowdays we use Bootstrap a lot as the base for our sites. But Bootstrap has a different grid-system, classes, structure and so on. So transforming Plones common viewlets, portlets and content into a bootstrap theme is fine. To also transform all the editing styles is much effort.
We prefer to theme the site with in-place editing. This makes sense for bigger customers or Intranet/Extranet sites.
If - for a public site - budget is limited, it saves time and money to not have in-place editing in the themed site.
Therefore we often use Diazo for the public face of a site while using Sunburst default-theme for editing.
This kind of customer has 1-3 people doing all the editing. Its easy to teach them how it works. If a login is still possible in the public facing site preview of private content is not a problem at all.
In this case we use two domains: the www.customer.tld and a cms.customer.tld.
So it comes that we need UI elements only for the themed site. Placing them in editing mode would confuse editors and it would need extra effort to style them at least minimal.
To overcome this we apply a BrowserLayer only if Diazo is active. Technically this it is done using a before traversal event subscriber. Here the subscriber.py:
from plone.app.theming.utils import isThemeEnabled from zope.interface import alsoProvides from zope.interface import Interface class IDiazoMarkerLayer(Interface): """Layer Marker Interface applied if Diazo is active """ def apply_diazo_layer(obj, event): if IDiazoMarkerLayer.providedBy(event.request) \ or not isThemeEnabled(event.request): return alsoProvides(event.request, DiazoMarkerLayer)
register the subscriber in configure.zcml:
... <subscriber for="Products.CMFPlone.interfaces.IPloneSiteRoot zope.traversing.interfaces.IBeforeTraverseEvent" handler=".subscriber.apply_diazo_layer" /> ...
No more needed!
The IDiazoMarkerInterface can be used as a usal Browserlayer: Register a view, viewlet or even a jbot template override in zcml with layer="IDiazoMarkerInterface" and it will only appear if the Diazo theme is active.
You can also think this further and add other conditions, it depends really on your use-case.