Skip to main content

pyramid_layer

https://secure.travis-ci.org/fafhrd91/pyramid_layer.png

pyramid_layer allows to address templates with two parameters, category and name. Also it is possible to use set of directories for each layer, in that case pyramid_layer searches templates in each directory. It allows to override templates without changing code. For example form library can define layer field:

>> ls ./fields/
.. bool.pt
.. file.pt
...
.. textarea.pt

In your application you can override any of this template by defining new layer for field category:

>> ls ./myproject/fields/
.. bool.pt

Usually top level directory is a category and file in directory is template. For example ‘form:view.lt’:

`form` - layer category
`view` - template name
`.lt`  - custom pyramid renderer factory

Layer can to be defined with add_layer config directive:

>> config = Configurator()
.. config.include('pyramid_layer')
..
.. config.add_layer('form', path='./path_to_form_dirctory/form/')

form directory can contain any template:

>> ./form/
..   view.pt
..   actions.jinja2

It is possible to use any of this templates as pyramid renderer path:

>> config.add_view(
..     name='view.html',
..     renderer='form:view.lt')

or :

>> config.add_view(
..     name='actions.html',
..     renderer='form:actions.lt')

It is possible to run python code before rendering template. There are add_tmpl_filter directive and pyramid_layer.tmpl_filter decorator:

>> def form_actions(context, request):
..     return {'url': ...}

>> config.add_tmpl_filter('form:actions', form_action, name='custom')

or:

>> import pyramid_layer

>> @pyramid_layer.tmpl_filter('form:actions', name='custom')
.. def form_actions(context, request):
..     return {'url': ...}

form_actions function gets call just before rendering template. Layer has to be defined with add_layer directve before registering template filter function.

Customization

Any number of layer categories can be registered and any number of layers can be registered in each category. It doesnt require to override all templates from category. For example it is possible to override just view.pt template:

>> config.add_layer('form', 'custom', path='path_to_form_directory_2/form')

and content of this new directory:

>> ./another_path/form/
..   view.jinja2

Now view view.html uses view.jinja2 template. But actions.html stil uses original template.

Another example, if you want customize bool field from ptah.form package all you need is to create some folder, add it as ‘fields’ layer, and put bool.pt template to this folder, something like that:

>> config.add_layer('fields', 'custom', 'mypackage:fields')

and

>> .mypackage/fields/
..    bool.pt

Request method

pyramid_layer also provides request method render_tmpl. It acccepts path:

..  ${structure: request.render_tmpl('form:actions')

.lt extension is optional in this case.

player

…

License

pyramid_layer is offered under the BSD license.

CHANGES

0.2 (11-01-2012)

  • Added layout subsystem

0.1 (10-30-2012)

  • Initial release

Metadata

Release files for pyramid_layer 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyramid_layer 0.2
File Size Uploaded Provenance Actions
pyramid_layer-0.2.tar.gz 14.8 kB Without provenance Details for pyramid_layer-0.2.tar.gz

Release files / pyramid_layer-0.2.tar.gz

Download URL pyramid_layer-0.2.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
adf24c5178f076e1f4a97ddd09679b2f7f7c4962456688861d72b9b05a5dcd35
BLAKE2b-256 checksum
How to use checksums
5b4a25d94c11706f251658e9e22791ba14ee1f49ffe2a10eaef520a5e835b8f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for pyramid_layer 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page