Skip to main content

Skin templates for repoze.bfg

Project description

repoze.bfg.skins provides a framework to register file-system page templates (ZPT) as components; we’ll refer to these templates as “skin templates”.

Templates registered using this framework are available as individual components within the component architecture and optionally as views, which are readily available for rendering through the router.

Any skin template may also be invoked as a macro using the METAL template language.

Package configuration

Within your repoze.bfg application package, include the ZCML configuration by adding the following statement to your project’s configure.zcml file:

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

Registering templates

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 template components, e.g.:

<bfg:templates
   directory="templates"
   />

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 component with a name based on the relative path to the template file (minus the extension, directory separators are replaced with a dot).

Optional parameters are content_type, request_type, permission`, ``class and for.

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

Using the class parameter, the components registered may be traversable views:

<bfg:templates
   directory="templates"
   class="repoze.bfg.skins.View"
   permission="some_permission"
   />

Each template will be registered as a traversable view component, optionally protected by a permission.

Macro support

Templates are also available as METAL macros using the function get_macro which is available from the template symbol to all skin templates.

The template symbol is tied to the current context and request. The usage of the macros object is demonstrated below:

<div metal:use-macro="template.get_macro('thumbnail')" />
<div metal:use-macro="template.get_macro('thumbnail', context)" />

A more elaborate example demonstrating macro slot support:

<div metal:use-macro="template.get_macro('thumbnail')">
   <span metal:fill-slot="label">
      This is a thumbnail
   <span>
</div>

Providing custom skin APIs

Helper utilities can be registered as skin apis and pulled in using the utility function get_api, which is available from the template symbol.

They must be registered as named component providing the ISkinApi interface, adapting on (context, request, template). A base class is provide for convenience:

>>> from repoze.bfg.skins.template import SkinApi

To look up a template API, simply use attribute-access on the api symbol.

<div tal:define=”api template.get_api(‘custom’)” />

Automatic detection of new template files

When the global configuration option auto_reload is set to “true”, skin templates are found at run-time.

Contributors

Malthe Borch <mborch@gmail.com> Stefan Eletzhofer <stefan.eletzhofer@inquant.de>

To contribute to development or get support, please visit the #repoze channel on freenode irc or write the mailinglist.

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.12.tar.gz (13.6 kB view details)

Uploaded Source

File details

Details for the file repoze.bfg.skins-0.12.tar.gz.

File metadata

File hashes

Hashes for repoze.bfg.skins-0.12.tar.gz
Algorithm Hash digest
SHA256 a3dd76a7eb3da48c33e3c1f8da43b48d2dbb1e1c2393ca0faa62f8bccc1f0774
MD5 d441928f0080f1dc7c29d852c96dbcf0
BLAKE2b-256 8a311360c1b93d138b05531ea61f2c10b0f69b85f33432eed1b375fe7f8b438a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page