Selecting a Skin Based on URL

by Laurence Rowe last modified Dec 06, 2009 10:28 PM
I want to have two skins for my site, one for the site administrator (the default plone skin) and one for the public (highly customised). This method uses Apache mod_proxy and Zope access rules to insert the appropriate plone_skin variable for different URLs.

Motivation

  • Selecting a skin using the normal mechanism is a chore and difficult to explain to users
  • Keeping all the web admin support in a custom skin can be limiting and adds to the page size
  • I want to try out some funky caching and I figured this would help

Prerequisites

  • Apache mod_proxy and the ability to edit your Apache httpd.conf file (if you want to choose the skin based on domain name)
  • You have Zope running on port 8080 with a plone site at /plone

Method 1 (Just using Zope)

  1. First set up your two skins in portal_skins > Properties. I use Plone Default as my public skin (with the customisations in the custom folder) and create a new skin called PloneStandard with the same layers as Plone Default except for removing custom. You will also need to check the Allow arbitrary skins to be selected box.
  2. Create a SiteRoot in your portal, leaving the Base and Path properties blank (you will need to delete the default / in Path).
  3. In your Zope root create a new folder (just a plain one, don't create a default document etc...) named admin.
  4. Inside /admin create a Python Script named access_rule (or whatever) with the following contents:
      from string import split,join
      REQUEST = container.REQUEST
    
      # Set the skin
      REQUEST.set('plone_skin', 'PloneStandard')
      # Tell absoulute_url and friends to use the correct path
      REQUEST.set('SiteRootPATH', '/admin')
    
      stack = REQUEST['TraversalRequestNameStack']
      # make the request for the plone site
      add_path = filter(None, split('/plone', '/'))
      add_path.reverse()
    
      stack.extend(add_path)
    
  5. Add a Set Access Rule to the folder, specifying access_rule

You should now be able to access the standard plone skin through http://yourzopeserver/admin and the customised skin through http://yourzopeserver/plone

Method 2 (Using Zope and Apache to choose skin based on domain name)

  1. Follow the steps above, but change the script in /admin to:
      from string import split,join
      REQUEST = container.REQUEST
    
      # Set the skin
      REQUEST.set('plone_skin', 'PloneStandard')
      # Tell absoulute_url and friends to use the correct path
      REQUEST.set('SiteRootPATH', '/')
      # and domain name
      REQUEST.set('SiteRootBASE', 'http://admin.yourserver')
    
      stack = REQUEST['TraversalRequestNameStack']
      # make the request for the plone site
      add_path = filter(None, split('/plone', '/'))
      add_path.reverse()
    
      stack.extend(add_path)
    
  2. Create another folder in the same way as /admin at /public setting the access rule to the following script:
      from string import split,join
      REQUEST = container.REQUEST
    
      # (Leave the default skin)
      # Tell absoulute_url and friends to use the correct path
      REQUEST.set('SiteRootPATH', '/')
      # and domain name
      REQUEST.set('SiteRootBASE', 'http://www.yourserver')
    
      stack = REQUEST['TraversalRequestNameStack']
      # make the request for the plone site
      add_path = filter(None, split('/plone', '/'))
      add_path.reverse()
    
      stack.extend(add_path)
    
  3. Edit the httpd.conf to put in the virtual servers (make sure mod_proxy is enabled):
      <VirtualHost *>
        ServerName www.yourserver
        ProxyPass / http://127.0.0.1:8080/public/
        ProxyPassReverse / http://127.0.0.1:8080/public/
      </VirtualHost>
      <VirtualHost *>
        ServerName admin.yourserver
        ProxyPass / http://127.0.0.1:8080/admin/
        ProxyPassReverse / http://127.0.0.1:8080/admin/
      </VirtualHost>
    
  4. Restart apache.

You should now be able to access the standard skin through http://admin.yourserver and the customised skin through http://www.yourserver

References

Contributed by Laurence Rowe