Selecting a Skin Based on URL
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)
- First set up your two skins in portal_skins > Properties. I use
Plone Defaultas my public skin (with the customisations in the custom folder) and create a new skin calledPloneStandardwith the same layers asPlone Defaultexcept for removingcustom. You will also need to check theAllow arbitrary skins to be selectedbox. - Create a SiteRoot in your portal, leaving the
BaseandPathproperties blank (you will need to delete the default/inPath). - In your Zope root create a new folder (just a plain one, don't create a default document etc...) named
admin. - Inside
/admincreate a Python Script namedaccess_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) - Add a
Set Access Ruleto the folder, specifyingaccess_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)
- Follow the steps above, but change the script in
/adminto: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) - Create another folder in the same way as
/adminat/publicsetting 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) - Edit the
httpd.confto 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> - 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
