Permalink
Browse files

* Updated project template to setup appropriate template loader and c…

…ontroller

  template to doc how to import render.

--HG--
branch : trunk
  • Loading branch information...
1 parent be91ae2 commit 60572014c8c568ca8e6b3583206da69c81ecbee6 @bbangert bbangert committed Mar 5, 2008
View
2 CHANGELOG
@@ -2,6 +2,8 @@ Pylons Changelog
=================
0.9.7 (**tip**)
+* Updated project template to setup appropriate template loader and controller
+ template to doc how to import render.
* Added documentation for render functions in pylons.templating.
* Adding specific render functions that don't require Buffet.
* Added forward controller.util function for forwarding the request to WSGI
View
5 pylons/templates/controller.py_tmpl
@@ -3,7 +3,6 @@ import logging
from pylons import request, response, session
from pylons import tmpl_context as c
from pylons.controllers.util import abort, redirect_to, url_for
-from pylons.templating import render
${importstatement}
# import ${package}.model as model
@@ -13,7 +12,9 @@ log = logging.getLogger(__name__)
class ${name}Controller(BaseController):
def index(self):
- # Return a rendered template
+ # Return a rendered template, first import the render function
+ # from pylons.templating import render_mako as render
+ # Then
# return render('/some/template.mako')
# or, Return a response
return 'Hello World'
View
23 pylons/templates/default_project/+package+/config/environment.py_tmpl
@@ -1,6 +1,11 @@
"""Pylons environment configuration"""
import os
+{{if template_engine == 'mako'}}
+from mako.lookup import TemplateLookup
+{{elif template_engine == 'genshi'}}
+from genshi.template import TemplateLoader
+{{endif}}
from pylons import config
{{if sqlalchemy}}
from sqlalchemy import engine_from_config
@@ -37,10 +42,18 @@ def load_environment(global_conf, app_conf):
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
{{endif}}
-
- # Customize templating options via this variable
- tmpl_options = config['buffet.template_options']
- tmpl_options['mako.input_encoding'] = 'utf-8'
-
+
+ {{if template_engine == 'mako'}}
+ # Create the Mako TemplateLookup
+ config['pylons.g'].mako_lookup = TemplateLookup(
+ directories=paths['templates'], input_encoding='utf-8',
+ output_encoding='utf-8', module_directory=os.path.join(
+ app_conf['cache_dir'], 'templates'),
+ )
+ {{elif template_engine == 'genshi'}}
+ # Create the Genshi TemplateLoader
+ config['pylons.g'].genshi_loader = TemplateLoader(paths['templates'])
+ {{endif}}
+
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
View
2 pylons/templating.py
@@ -25,7 +25,7 @@
its full name since it will likely be used extensively and it's much
faster to use ``c``. Of course, for users that can't tolerate
one-letter variables, feel free to not import ``tmpl_context`` as
-``c`` as both names are available in templates as well.
+``c`` since both names are available in templates as well.
Example of rendering a template with some variables:

0 comments on commit 6057201

Please sign in to comment.