Switch skin based on domain
This How-to is intended for:
Developers
Sites some times need to show the public and logged in users different skins. This is especially true as the public skin diverges more and more from the standard plone design. It is better to keep the standard plone skin for logged in users who are managing content to make use of all of the UI that plone provides content managers and to reduce the work load on developing the skin for a site. This can be done by either setting up separate domains for logged in access or by checking the users membership status
Setting skin by domain
Requirements
- Site accessible by different domains
- Skins created and installed
- Public site accessible via www.example.com or example.com with a skin called "PublicSkin"
- Logged in site accessible via admin.example.com with the default plone skin
What to do
- First we need to create a "Script (Python)" at the root level of the Plone site's ZMI with the id 'applyRetailView':
-
request = context.REQUEST
url = request.get('URL')
if url.startswith('http://example.com') or url.startswith('http://www.example.com'):
context.portal_url.getPortalObject().changeSkin('PublicSkin') - in the ZMI at the root of your Plone site, select Set Access Rule from the add menu, and enter applyRetailView as the id.
Sources
Martin Aspeli's Creating public websites with staging and custom skins - Setting up PloneSetting skin by Membership
Requirements
- Skins for Public and Logged in
What to do
In the root level of the Plone site's ZMI create a "Script (Python)" with the id 'applyRetailView'from Products.CMFCore.utils import getToolByNamein the ZMI at the root of your Plone site, select Set Access Rule from the add menu, and enter applyRetailView as the id.
mt = getToolByName(context, 'portal_membership')
if mt.isAnonymousUser(): # the user has not logged in
context.portal_url.getPortalObject().changeSkin('PublicSkin')