Resource folders

Description

How to use Zope 3 resource directories to expose static media files (css, js, other) in your Plone add-on product

Introduction

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.

ZCML resourceDirectory

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

Grok static media folder

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.

Table Of Contents

About Plone

This is documentation for Plone®. Plone is a popular, open source, content management system written in Python programming language.




Edit this document

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.

  1. Go to Resource folders on GitHub.
  2. Press Fork and edit this file button.
  3. Edit file contents using GitHub's text editor in your web browserm
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on Github.

For basic information about updating this manual and Sphinx format please see Writing and updating the manual guide.