Is there a replacement for collective.editskinswitcher in Plone 5(.2)?
We have the requirement to show switch between standard Plone theme and a custom Diazo theme based on role(s) of the current user and/or public hostname (www.domain.com vs. edit.domain.com).
it does if you are using a single theme and not using different domain names but rather switching to a simple part of teh same theme when doing admin type actions like edit, site setup etc. Means you can use the same domain and switch dynamically. Works pretty well in reality. We use it for all out sites.
but you can do it another way. I've no idea of the status of other solutions.
mekell via Plone Community wrote at 2022-6-4 17:38 +0000:
...
Is it in some way possible to present/render different themes based on the url/domain?
Plone 5 uses three skin mechanisms: portal_skin, skin layer views
and the theme which controls the output transform.
portal_skin can be controlled via cookies or request parameters.
The applicable skin layers are determined by the interfaces provided by the
current request object. The theme is determined via IThemingPolicy(request), thus can also be controlled via the
request object.
You could implement your custom logic in a traversal hook
(e.g. a SiteAccess AccessRule). The challenge will be that
your settings are not overridden by subsequence traversal hooks.
At your place, I would look how collective.ediskinswitcher
has solved this problem (it had to handle the first 2
of the 3 skin types; its approach will be extendable to the 3rd as well).
from plone.app.theming import utils
def switch_theme(object, event):
if "www.mydomain.org" in event.request["ACTUAL_URL"]:
for theme in utils.getAvailableThemes():
print(theme.__name__)
if theme.__name__ == "barceloneta":
try:
#the following raises "'NoneType' object has no attribute 'currentTheme'"
utils.applyTheme(theme)
print("applyTheme", theme)
except Exception as e:
print("exception", e)
Is utils.applyTheme the right place to set the theme? Why is it None?
How do I decide when to switch_theme? A page request triggers subsequent requests like the following and the theme should not be changed on every (sub)request:
mekell via Plone Community wrote at 2022-6-7 15:44 +0000:
@dieter: following your tipps I've tried the following but I don't know whether I'm on the right track:
...
Is utils.applyTheme the right place to set the theme? Why is it None?
I do not think so.
Your use case requires different behavior based on
individual request properties. As you are aware,
you do not want to change persistent state. applyTheme does not depend on the current request:
it sets the "global" (request independent) theme
and will modify persistent state.
As I wrote earlier, there are 3 different kinds of skinning.
If you need only to adapt the theming kind (i.e. the output transform)
to depend on the request,
you could follow Espen's suggestion
(i.e. use a fixed transform but let it behave slightly differently
depending on request specific information put into the response).
I likely would use a viewlet to add the necessary information into
the response.
Alternatively, you could override the IThemingPolicy
adapter registration (if necessary with z3c.unconfigure),
look in your adapter at whatever request properties you
like and return the appropriate theme.
It is really better to use data-xxx attributes, they exists exactly for this kind of purpouse. Url must always be encoded when inserted in attributes but we know exacly the value here, so it should not be a problem (just encode & and " but this chars should not be in a portal url).
<!-- assign html template to default content -->
<rules if-not-content=" //*[@data-template='product_filter_view'] | //*[@data-template='collection_album_view']" >
<theme href="html/index-mega-responsive.html" />
</rules>
<!-- Replace title with Plone's page title
we add our company name first
if breadcrumbs-1 is a link, we are on a category subpage or lower
and also include the main category
if there is a data-template product_item_view we are on a product page
and insert text from .item-title > h4 and double-width horizontal separator
-->
<replace css:theme="html head title" mode="raw">
<title>
<xsl:choose>
<xsl:when test="//*[@id='breadcrumbs-1']/a">
PNZ:
<xsl:value-of select="//*[@id='breadcrumbs-1']/a/text()" />,
<xsl:choose>
<xsl:when test="//*[@data-template='product_item_view']">
<xsl:value-of select="//*/header[@class='item-title']/h1/text()" />
—
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
PNZ Produkte GmbH:
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="//html/head/title" />
</title>
</replace>