Using Breve with Pylons
  1. Installation
  2. Configuration
  3. Writing a Controller
  4. Known Issues
  5. Back to Main Documentation

Configuration

To use Brevé with your Pylons project, a couple of additional steps are required. These steps have changed with almost every version of Pylons (and will be changing again for 0.9.7 when Pylons deprecates Buffet).

For Pylons 0.9.6

Edit myapp/config/environment.py and add the following:

# CONFIGURATION OPTIONS HERE (note: all config options will override any
# Pylons config options)
breve_opts = { 'breve.root': 'myapp/templates',
               'breve.tidy': False,
               'breve.debug': False }
config.add_template_engine ( 'breve', 'myapp/templates', breve_opts )

For Pylons 0.9.7

Pylons 0.9.7 has disposed of the Buffet adaptor and created its own way of dealing with template engines. This new method is quite simple and allows for maximum flexibility. To use Brevé with a Pylons 0.9.7 project, simply add the following to config/environment.py:

config [ 'pylons.app_globals' ].breve_opts = {
    'root': 'myapp/templates'
}

You can add as many Brevé-specific options as you like here. They will be passed to the Template object as instantiation arguments.

Next, you must use the Brevé adapter in your controller:

from breve.plugin.pylons_adapter import render

class MyController ( BaseController ):
    def index ( self ):
        c.message = 'hello, world'
        return render ( 'index' )

This is not the only way to render a Brevé template (you could create a new adaptor modeled after the one provided), but it's enough to get you started.

Writing a Controller

Using Brevé from your controller is quite easy. Simply attach variables to the Pylons context variable c as usual and then render your template:

def view ( self ):
    c.title = 'A simple controller'
    c.content = 'Hello, world'
    return render ( 'page' )

and in your template:

html [
    head [ title [ c.title ] ],
    body [ div [ c.content ] ]
]

Known Issues

Pylons has changed how it deals with template engines three times that I'm aware of: 0.9.5, 0.9.6, and again in 0.9.7. This can make it confusing to find correct documentation for the version you are using. If you cannot get Brevé to work, please drop a note on the list.

edit page
Back to top
Rendered using Brevé 1.3.0Copyright © 2007, Cliff Wells