ResourceRegistries
Registering CSS style sheets and Java scripts with 'portal_css' and 'portal_javascripts'
Adding new style sheets and Javascript scripts in Plone 2.0 was problematic, because all such resources were hard-coded into page templates. In Plone 2.1, ResourceRegistries provides the tools 'portal_css' and 'portal_javascripts' which can be used to register CSS style sheets or Javascript files, respectively. Resources can be loaded conditionally, determined by a TALES expression, and are easily managed using the tools' APIs.
RichDocument registers a custom stylesheet with 'portal_css' [PORTALCSS] in its 'Install.py'::
portal_css = getToolByName(self, 'portal_css')
portal_css.manage_addStylesheet(id = 'richdocument.css',
expression = 'python:object.getTypeInfo().getId() == "RichDocument"',
media = 'all',
title = 'RichDocument styles',
enabled = True)
Notice how the 'expression' variable is set to a TAL condition that is evaluated to determine if and when the style sheet should be included.
Use the "DocFinderTab":http://plone.org/products/docfindertab on 'portal_css' and 'portal_javascripts' to find out what else these tools can do.
If you are interested in creating a visual style/theme for Plone, the "DIYPloneStyle":/products/diyplonestyle skeleton product [DIYPLONE] should get you started.
.. [PORTALCSS] Note that it is not strictly necessary to use 'portal_css' in RichDocument's case, because the stylesheet is only used in the 'richdocument_view*' templates, which could have used 'css_slot' to define them as normal. However, that would not have made as good a demonstration. ;-)
[DIYPLONE] This supersedes the older "SimplePloneStyle":/products/simpleplonestyle product, which may still be useful as an example.
Previous:
Controlling creation
