Set skin for folder
We are going to create an External Method to select the skin during an Access Rule when visiting a folder. This method may give you problems with caching - you are adviced to read it carefully and determine whether it is really useful to you. Also remember that it is possible in Plone for individual users to be allowed to set their own skins, so if you want certain users who primarily access certain folders to use a given skin, it may be better to let these users pick a different skin from the default one.
- Create a file called
set_skin.pyin the "Extensions" folder in your Zope (Plone) installation (ie$ZOPE/ExtensionsorData\Extensions- not..Products\CMFPlone\Extensions, for example) - Edit the file using your favorite editor, and enter this code:
def bindSkin(self): REQUEST=getattr(self, 'REQUEST', None) if REQUEST: self.changeSkin('Plone Tableless')
I am setting the skin to Plone Tableless here.
- Open your Plone site and create a new folder in Plone to test this recipe in.
- Open up the folder in the ZMI, from the "Add" dropdown in the upper right, pick
External method, click add. Enter anidof your choice (ex:bindPublicSkin), title doesnt matter, the name of the script file, ieset_skin.pyand the name of the method in the file, iebindSkin(glance above to see). - Finally, we set this method as the access rule for the folder we are in (Please make sure you are using a testfolder). So, now pick
Set access rulefrom the add dropdown and then enter theidof the external method, iebindPublicSkin.
Now go test by accessing the folder, neat huh?
Problems
If you run into trouble (I did) here are two tips:
- You can disable the access rule if it locks you out of the folder by simply adding
_SUPPRESS_ACCESSRULEto the URL when accessing the folder. Iewww.myplonesite.com/afolder/_SUPPRESS_ACCESSRULESee the comment on the zope services page - If the script bugs and you get a site error, dont panic! You can edit the script (but I had to restart zope using restart button in the control panel of the ZMI) and try again.
But really, since I went through that it should just work. :)
Issues
- There's also the CMFUrlSkinSwitcher product in the collective that allows you to use regular expressions to programmatically switch the skin depending on these rules
- You may get problems with style sheets etc. being cached and therefore not correctly updating from one skin to the next. How big of a problem this is will depend on your skin. You can get around this by customising
headerin inportal_skins/plone_templatesso that plone.css and ploneCustom.css are referenced from a relative url: i.e. replace@import url($portal_url/plone.css)with@import url(plone.css). However, this will probably slow your site down, as the browser won't be able to cache these stylesheets efficiently.
Resources
Did you get all of this? No? ;) Glance at this:
- Using external methods
- Again, on access rules, zope services
Original recipe
This is the recipe written by runyaga on zopelabs that I tried, I have updated one thing. You can find it here
There is also another recipe

