virtualenv --no-site-packages newenv
source bin/activate
paster create -t pyramid_routesalchemy webhelp
cd webhelp/webhelp
edit webhelp/development.ini and put near the top:
mako.directories = webhelp:templates
edit webhelp/webhelp/__init__.py and put:
config.add_subscriber('webhelp.subscribers.add_renderer_globals',
'pyramid.events.BeforeRender')
config.add_route('webhelper', '/webhelper')
config.scan()
above:
return config.make_wsgi_app()
edit webhelp/webhelp/views.py, add:
from pyramid.view import view_config
@view_config(route_name='webhelper', renderer='webhelper.mako')
def webhelper(request):
return {'data':'data', 'email1_count':1, 'email2_count':2}
create webhelp/webhelp/subscribers.py:
from pyramid.threadlocal import get_current_request
from pyramid.exceptions import ConfigurationError
from pyramid.url import route_url
from webhelp import helpers
def add_renderer_globals(event):
request = event.get('request')
if request is None:
request = get_current_request()
globs = {
'h':helpers,
}
event.update(globs)
create webhelp/webhelp/helpers.py:
from webhelpers.text import plural
from webhelpers.html.tags import form
create webhelp/webhelp/templates/webhelper.mako:
<p>
here's my ${data}
</p>
You have ${h.plural(email1_count,'message','messages')}.<br/>
You have ${h.plural(email2_count,'message','messages')}.<br/>
${h.form('asdf')}
Briefly, any import in helpers will be exposed to your template as
h.whatever. If you just want to use normal webhelper rather than a
form library you can. Also, I use deform with both Mako and Jinja2,
and unless you need to change the widgets, it doesn't really matter
much that the templates use chameleon. I've written several projects
and except for one minor case, haven't modified the templates.
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.