Description
How to use Zope 3 resource directories to expose static media files (css, js, other) in your Plone add-on product
Resource folders are Zope 3 way to expose static media files to Plone URL mapping.
Resource folders provide a mechanism which allows conflict free way to have static media files mapped to Plone URL space. Each URL is prefixed with ++resource++your.package resource identified.
If you want to customize media folder mapping point, you need to use Zope 3's resourceDirectory directive.
Below is an example how to map static folder in your add-on root folder to be exposed via ++resource++your.product/ URI
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
xmlns:i18n="http://namespaces.zope.org/i18n"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="your.product">
<!-- Register the installation GenericSetup extension profile
(needed for portal_css and portal_javascripts XML import) -->
<genericsetup:registerProfile
name="default"
title="Your add-on product name"
directory="profiles/default"
description="Your add-on product description"
provides="Products.GenericSetup.interfaces.EXTENSION"
/>
<!-- Resource directory for static media files -->
<browser:resourceDirectory
name="your.product"
directory="static"
/>
<!-- -*- extra stuff goes here -*- -->
</configure>
Furher reading
Learn more about Grok and Plone integration.
The easiest way to manage static resources is to make use of the static resource directory feature in five.grok. Simply add a directory called static in the package and make sure that the <grok:grok package="." /> line appears in configure.zcml.
Example how to include yourproduct.app/static folder as ++resource++yourproduct.app URL.
<configure
...
xmlns:grok="http://namespaces.zope.org/grok">
<grok:grok package="." />
</configure>
If a static resource directory in the example.conference package contains a file called conference.css, it will be accessible on a URL like http://<server>/site/++resource++example.conference/conference.css. The resource name is the same as the package name wherein the static directory appears.
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.
For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.