Personal tools
You are here: Home Documentation Tutorials RichDocument: Creating content types the Plone 2.1 way ResourceRegistries
Support

Get Help

Join our chat rooms or support forums if you have more specific questions.

Plone Training
Learn how to design, build, and deploy a website in Plone through one of the numerous Plone training sessions around the world.
Find Plone training…
 
Document Actions

ResourceRegistries

Registering CSS style sheets and Java scripts with 'portal_css' and 'portal_javascripts'

Martin Aspeli

This tutorial will teach you how to create content types the Plone 2.1 way, using the ATContentTypes library, by following the example of RichDocument, an extension of Plone's standard Page/Document type.
Page 10 of 17.

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 styles heet with 'portal_css'[1] 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 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 skeleton product[2] should get you started.

[1] 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. ;-)

[2] This supersedes the older SimplePloneStyle product, which may still be useful as an example.

 
by Martin Aspeli last modified September 5, 2005 - 10:59 All content is copyright Plone Foundation and the individual contributors.

For any issues with the web site functionality, please file a ticket.

Please consult the policy on plone.org content if you want your content published on this site.

Servers and hosting by