Practical: Adding a Style Sheet to the Registry Through the Web

by Anne Bowtell last modified Jul 31, 2009 06:36 PM
Contributors: Yuri Carrer
Basic operations of the CSS-and Javascript-registries – and a truly minimal example of how to use them in real life. As a simple example of the most basic functionality, we'll add and register a minimal stylesheet that adds to the background of your Plone a terrible red color.

To use one of the registries, you have to

  1. Have a resource (for example a File) in your Skin with some CSS or JavaScript in it (this could, for instance, be in the custom folder of portal_skins).
  2. Make an entry in the corresponding registry (for example portal_css) with the id of the resource.

Make a Style Sheet

  • Go to Site Setup > Zope Management Interface and navigate to portal_skins/custom
  • From the add-item menu, select File
  • Give your new file an id of 'css-demo.css'
  • Paste the following content into the file:
    body{ background-color : red }
  • …and save it

Add it to the CSS Registry

The registries are two tools that live only in the Zope Management Interface (ZMI); they have no interface in the Plone user-interface itself. However, you can easily find them when browsing the ZMI of your Plone site - look for portal_css and portal_javascript

  • Go to Site Setup > Zope Management Interface and click portal_css.  Once selected, the CSS Registry ( the one we use for this example - the JavaScript one is almost exactly the same) will present an interface displaying all the registered resources (in the case of the CSS Registry, the resources are CSS files).
  • Make sure that you tick the debug mode checkbox. This will ensure that you see your changes immediately.
  • Scroll to the bottom of the form, where there is a form for adding a style sheet

  • In the id field, enter 'css-demo.css'  (leave the other values as they are by default for now)
  • Voila! – view your Plone site and you'll easily notice its (admittedly quite horrifying) shiny red background color!

The Technical Explanation

Each entry in the registries has an id that references a resource that can be found in the current Plone acquisition context. Technically it could be a tool or a utility or anything that has a name and is available, but most commonly it will be a File object ( for static CSS and JS) or a DTML Method (for dynamic variable replacement). The Resource Registries makes no difference as to what the object is, as long as it can be found and called, rendered or printed as a string.