Skip to main content

Skin templates for repoze.bfg

Project description

repoze.bfg.skins provides component-based templates that may be used both as views and template macros. It’s compatible with the repoze.bfg framework.

We’ll refer to these templates as “skin templates”.

Including the repoze.bfg.skins ZCML

Within your repoze.bfg application package, include the repoze.bfg.skins ZCML registrations by modifying your application’s configure.zcml. Add the following ZCML to that file:

<include package="repoze.bfg.skins" file="meta.zcml"/>

Templates as views

Once you’ve included the repoze.bfg.skins ZCML, you may use the ZCML directive <bfg:templates> to register a directory with templates and make them available as view components, complete with security and adaptation:


The directory parameter indicates a package-relative path that should point at a filesystem directory containing chameleon.zpt templates with the extension .pt. Each template located inside the directory (recursively) becomes a view component and given a name based on the relative path to the template file (minus the extension, directory separators are replaced with a dot).

The skin template components are callables and return a WSGI response object.

You can override which “request type” the skin is for by using the request_type attribute:


See the repoze.bfg view request type documentation for more information on request types.

If you want to protect your templates with a specific permission, you may as well by using the permission directive:


If you want the templates to only be displayed for specific context (model) types, use the for parameter:


The request_type, permission`, and ``for parameters can be combined freely.

Templates as macros

Templates are also available as METAL macros using the symbol macros which is available to all skin templates (it may be instantiated manually, too).

The macros object is tied to the current request; the context is the template context, if one does not explicitly provide one. The usage of the macros object is demonstrated below:

<div metal:use-macro="macros.thumbnail" />
<div metal:use-macro="macros(some_context).thumbnail" />

As with all METAL macros, the macro slot functionality is available.

Template API support

To aid template designers, applications and libraries can make APIs available to templates. Simply register a named component for the repoze.bfg.skins.interfaces.IApi interface that adapts on (context, request).

In the template, get the api by using the api symbol:

<div tal:define=”my_api api.my_api” />

The api symbol is available to all skin templates.

Automatic detection of new templates

In debug-mode, skin templates are automatically picked up and registered. The way this works is that there’s an event listener registered for the repoze.bfg.interfaces.INewRequest event such that directories are searched for new files before any application logic is run, prior to each request.


This package was put together by Malte Borch <>. To contribute to development or for support, please visit either #repoze on freenode irc.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repoze.bfg.skins-0.1.tar.gz (10.7 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page