Creating a new theme for Plone: a real-world example (Plone 2.1, 2.5)
In this tutorial, Alexander Limi will show you how to take a default Plone site and put a totally different look on it. (Not updated for Plone 3.0)
Introduction
Introduction to the tutorial, and the new theme approach made possible using Plone 2.1 and later versions.
[DEPRECATION WARNING: As of 3.0, this approach is no longer recommended. In Plone 3.0, we no longer use DIY Plone Style for creating themes. Instead, we use buildout for setting up a development environment, and paster and ZopeSkel for creating a theme product. Search for these items as well as for documentation on managing viewlets and managing portlets in 3.0 (found in the Visual Theming area of plone.org/documentation). More documentation on theming for 3.0 is coming soon.]
With Plone 2.1 and up, we have a new method of skinning Plone that makes it a lot easier than the approach used in earlier versions of Plone.
I won't dwell too much on how it was done earlier apart from saying that it was based on taking the existing Plone CSS, overriding the existing CSS rules and creating a new skin based on this. This approach had numerous problems:
- It was very complex if you didn't know much about CSS
- It was prone to breakage when upgrading to new versions of the Plone CSS (even minor changes would make your theme change
- It caused the CSS output files of Plone to be very large
The new approach
With Plone 2.1 and up, we have a new infrastructure component called ResourceRegistries. This component allows us to split up CSS and Javascript on the server side, so it can be managed in a sane way. We can attach conditional checks on parts of the CSS/JS, and merge it all to a single CSS/JS file on the way out, so that the browser only sees one CSS file to reduce the amount of file requests needed. In later versions, RR also added CSS and JS compression to keep file sizes down.
What this means for us when we want to create a Plone Theme, is that we can *selectively disable* parts of the Plone user interface CSS. A very common approach is to keep the CSS for authoring (the green border, the forms CSS), and customize only what people see when they are not logged in. This has several advantages:
- We can start with a blank slate, and apply our CSS without interference from Plone
- We can reduce the download size of the CSS to only what we need
- The theme becomes much more resilient to changes in Plone itself
The reason this approach is more robust when it comes to keeping compatibility with future Plone versions, is that it is only relying on HTML IDs and classes, which should rarely change. (Realistically, there are some changes now and then to the classes and IDs too - but these are much less frequent than other changes, and the Plone Team tries to leave them intact if possible)
There are three ways of changing Plone's appearance:
Simple changes --
Replacing the logo and adjusting the colors. I won't cover this here, but it's covered in most of the books and in a couple of how-tos.
Comprehensive --
Replacing all the styles that are visible to the public, but keeping the basic widget styles. May involve simple changes to main_template, but nothing radical.
Full --
Starting from scratch and replacing all the CSS and rewriting templates (not recommended, will be a maintenance nightmare)
I will cover the Comprehensive use case.
Why keep the Plone structure?
Accessibility -- Plone has been engineered to be friendly for users with motor or vision disabilities. This takes a lot of effort and testing — with Plone, you get it for free.
Search engine visibility -- Out-of-the-box, a blank Plone site has the potential for a very high Google Rank. For plone.org itself, we have a Google Rank of 9/10, the same as Microsoft, IBM and similar massive entities on the web. We have spent a lot of time optimizing Plone for search engines. Google loves Plone. Plone loves Google. (Trivia: the only site I have found out there with a 10/10 Page Rank is the W3C page — anybody know of others? :-)
A note about terminology
Throughout this tutorial, I use the word "theme" to describe the collection of visual modifications done. In other parts of the Plone literature, this is described as "skinning" and the end result a "skin". The reasons we're trying to move away from this terminology are several:
1. In Plone terminology, a "skin" can be both template, CSS and code modifications. We try to keep the visual themes separate from the code and template customization as far as possible, and use the word "theme" to convey that it is **only** about visual changes.
2. We encourage you to keep your other Plone modifications in a separate file system product, this makes the visual modifications / theme part of the equation much more reusable and simple.
For example, in our company we usually stick to the following product naming convention, with "Site" being the customer or project name:
SiteTheme -- Holds the visual theme, and the other visual elements that are general (logos, background images, etc).
SiteTweaks -- Holds small modifications to the templates, behavioral changes to the templates and Python scripts.
SiteSetup -- Using the GenericSetup infrastructure in Plone 2.5 or up (or CustomizationPolicies in Plone 2.1 and older), this product holds the stuff that needs to be set up when you instantiate a site — configuration changes, SQL connections, etc.
As for infrastructural components, we never name these after the customer/project, but try to come up with generic names (as we often end up open sourcing these solutions and want neutral names for these).
Toolchain
Quick walk-through of the different tools we have at our disposal to create and inspect CSS-based designs.
Preparing Zope & Plone
If you are creating the skin on the file system (recommended) rather than through the ZMI there are several methods you can use to make debugging simpler.
Zope Debug Mode
Running Zope in debug mode enables skin changes to be reflected on the site instantly. There are several ways to enable this:
- in etc/zope.conf set:
debug-mode on
then restart zope using the following (in order to display error log to your console)zope_instance/bin/runzope
- OR start zope using :
zopectl fg
- If you installed using the Windows installer version of Plone there is an option to run in Debug mode in the Plone Program menu.
Reloading Products
If you are not using debug mode there is still a way to update changes to a skin product using the reload option. To enable this option you need to have a refresh.txt file inside your product folder (DIYPloneStyle's generator creates this by default).
- In the ZMI, go to Control Panel -> Product Management -> Name of your skin product
- load the Refresh tab and click the 'Refresh this Product button' to reload the product.
CSS Resource Registry
To help the performance of a Plone site, portal_css merges all the stylesheets for a page into just one CSS file. To make debugging you custom css simpler you can use its debug mode which prevents this merge:
- In the ZMI go to Plone Site -> portal_css
- Tick the Debug mode box and press the save button.
DOM Inspectors
Document Object Model or DOM for short, is a term used to describe how a html page (or xml document) is structured and provides an API to access. The browsers convert the raw text from the html/xml file into a DOM and then use it to apply CSS and other transformations.
So why is this useful for us? Well the HTML and CSS in Plone's default skin does a lot of things well – the downside of all this power is that its complicated. So sometimes you want to change just a simple element but you don't know how to get a handle on that item to write the relevant css.
This is where the DOM Inspectors come in...... You can see the structure of the page in a tree and receive visual feedback as you traverse all the elements. Once you've found it you can easily find out all the attributes such as class, id, and parent elements.
Firefox DOM Inspector
When you install firefox, make sure you enable the Web Developer tools option from the Custom installation menu.
Firefox comes with a very useful DOM inspector tool. To open it go to the Tools menu and look for it near the bottom. Alternatively in Windows Firefox press Ctrl + Shift I , or in Mac Firefox Apple key + Shift + I.

First thing you'll probably have to do is maximise the DOM Inspector – it works much better with a large screen.
Then go to the File menu and select Inspect a URL. Enter the address for the site you want to inspect and the page will load up in the bottom pane of the DOM Inspector.
There are two basic ways of using the Inspector :
Traversing the tree
In the tree pane in the top left, use the + icons to expand each node. Starting with #document, then HTML and BODY as you expand you reveal more and more of the elements; Notice that there are columns for id and class to help you find where you are.
As you click on each element you will see the the relevant visual element flashing below in the browser pane.
Now, Lets find the navigation tree elements:
- Expand the DIV with id visual-portal-wrapper (the Plone specific container for all the page)
Locate and Expand TABLE with id portal-columns (this contains the central part of the page)
Expand TBODY, TR and then TD with the id portal-column-one (left column)
Finally expand the DIV with the class visualPadding to reveal the portlet items including the portlet-navigation-tree

Select Element by Clicking
Go to the search menu and choose the last option 'Select Element by Click'
Now go to the browser pane and click on the element you want to highlight in the tree.
To find another element you need to repeat the first step again.

Web Developer Extension for Firefox
The Web Developer Extension adds a very powerful & useful toolbar to your firefox browser which really helps while developing Plone Skins.
Here are some of the many features it offers:
- Edit CSS instantly - no need to make changes in the ZMI or FileSystem and refresh.
- View Style information - click on elements of the page to bring up the relevant CSS declarations.
- Disable all/specific stylesheets
- Apply new stylesheets
- Display outlines of all/specific elements on the page (e.g all <div>, or <ul>)
- Generate a list of all images on the page.
- Resize the browser window to common or custom sizes e.g. 1024 x 768, 800 x 600 etc.
- Display detailed information about Forms, Links, Meta Tags, HTTP Headers, Document Size and more.
- Validation: for HTML / CSS / RSS / Accessibility / Links
- Ruler - Measure how tall/wide parts of the page are. No need to guess how many pixels your CSS is out any more!

FireBug extension for Firefox
FireBug is the DOM inspector on steroids, and is insanely useful for inspection of HTML, CSS and Javascript.
Once installed it sits quietly in Firefox's status bar (below the browser window). Everytime a page loads it checks for and logs any errors it finds into its console. If the page has no errors on it displays a green tick icon otherwise it displays a red cross with and lists the number of errors found.


To use all the cool features simply click on either of these icons to display the FireBug pane:

Legend
- FireBug Icon (green tick)
- Inspector tab - use to switch from console mode (list of errors and alerts) to inspection mode.
- Inspect button - use this to enable/disable element selection using the mouse. When enabled you can hover over elements in the browser pane and select the elements you want to inspect.
- Source & Style tabs - switch between these to view the HTML or the selected element's CSS attributes.
From here you can view errors in the Console or switch to the Inspector tab to display the pages HTML interactively. Click on the arrow icons to expand/collapse each tag and traverse to your required element. Alternatively use the inpector button to choose the element from the website itself.
View Source Chart Extension for Firefox
The View Source Chart Extension makes understanding the structure of an HTML document so much easier.
Once installed simply right click anywhere on the page you want to view and look for "View Source Chart". This will load the chart up in a new window:

You will notice that different elements have different colors for easy readability, and each container is collapsible by clicking on it which can really help you isolate the items you are interested in.
Now that you have the basic tools for looking up classes and IDs on the element you want to change, we can continue with putting a new look on Plone.
Real-world use case
For our purposes, we will show how to build a theme from a Photoshop mock-up.
The starting point for our work is the excellent "DIYPloneStyle":/products/diyplonestyle product, which makes it easy to create a skeleton for your theme product. Big kudos to "David Convent":/author/davconvent for providing this handy piece of software that makes our job so much easier.
A proper foundation
Before we start adding our CSS styles, we need to create the basic foundation for our theme. This is essentially a blank skeleton product that we can put our images and CSS inside.
This provides an excellent starting point for our theme.
Scaffolding
Before we can start writing CSS, we are going to do some structural changes and export the graphical elements.
Adding CSS styles
Finally, it's time to apply our CSS styles. Each step is illustrated by an image showing the progression of the theme.
Unmodified theme
After creating our MyTheme in the previous steps of the tutorial and installing it, we have the following:
Not too pretty, but that's what we're about to change. The thing that you should notice here is that it is using the standard Plone style for the View/Edit tabs, which we wanted to keep for this design.
Header styles
First up, the site header.
Still doesn't look like much, but we have the logo in place, at least.
Basic styles
Adding the basic body styles.
One step at a time, getting there eventually. :)
Background image styles
Adding a background image and locking the width of the design.
Amazing what adding a simple background does to the design, isn't it? Onwards!
Headline and paragraph styles
Adding styles for headlines and paragraphs.

List styles
Making the lists be displayed inline and without bullets.
Wow, that really cleaned up things, didn't it?
Portlet and navigation styles
Adding proper styles to the portlets and the navigation tree in particular.
Wow, now we're talking. It's starting to look like the proper design now, just needs some tightening of the margins and positioning.
Re-positioning the navigation
Removing redundant margins on the portlets and navigation tree.
Almost there! Can you see what's missing? That's right, the footer.
Footer styles
Final element, styling the footer.
Now, that wasn't too bad, was it? Of course, if you haven't ever done CSS, this is probably a bit overwhelming, but fortunately there are lots of good CSS resources on the web.
Go forth and create — or port existing — beautiful themes for Plone and upload them in the "products area":/products!
Tips for creating your own Plone Themes
Some useful tips for making your site designs stand out and work well with future versions of Plone.
Do's and don'ts for themes:
Don't add behaviour --
You never know what kind of site you're going to live inside — keep Javascript and template changes (apart from changes to the purely structural templates like 'main_template' or 'global_logo') outside the theme product.
Don't create external dependencies --
If you have a portlet that pulls data from an SQL database, that portlet should live in a separate product, not in the theme product
Do reuse markup --
The headers in our example look very different from the original ones, but are still h1 tags.
Do change the design slightly --
Don't be afraid to deviate a little bit from the designer's mock-up if it goes against good web usability rules — but be ready to defend it in front of the customer, and tell him why you did it differently.