Set skin for folder

by mawi — last modified Dec 06, 2009 10:13 PM
Shows how to select a different skin than the main site skin for a given 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.py in the "Extensions" folder in your Zope (Plone) installation (ie $ZOPE/Extensions or Data\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 an id of your choice (ex: bindPublicSkin), title doesnt matter, the name of the script file, ie set_skin.py and the name of the method in the file, ie bindSkin (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 rule from the add dropdown and then enter the id of the external method, ie bindPublicSkin.

Now go test by accessing the folder, neat huh?

Problems

If you run into trouble (I did) here are two tips:

  1. You can disable the access rule if it locks you out of the folder by simply adding _SUPPRESS_ACCESSRULE to the URL when accessing the folder. Ie www.myplonesite.com/afolder/_SUPPRESS_ACCESSRULE See the comment on the zope services page
  2. 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 header in in portal_skins/plone_templates so 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:

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