> ERRATA: Try this instead.

def jinja2(f):
     def _jinja2():
         d=f()
         if isinstance(d,dict):
             from jinja2 import Environment, FileSystemLoader
             env = Environment(loader=FileSystemLoader(os.path.join 
(request.folder,'views'))
             template = env.get_template(response.view)
             return template.render(**d).encode('utf8')
         else: return d
     return _jinja2


On Dec 26, 2008, at 3:54 AM, Massimo Di Pierro wrote:

> Hi Italo,
>
> I played with this some more. Try define the following decorator  
> (in a model or controller)
>
> def jinja2(f):
>      def _jinja2():
>            d=f()
>            if isinstance(d,dist):
>            from jinja2 import Environment, FileSystemLoader
>            env = Environment(loader=FileSystemLoader(os.path.join 
> (request.folder,'views',request.controller))
>            template = env.get_template(response.view)
>            return template.render(**d).encode('utf8')
>      return _jinja2
>
> Those controller actions marked with decorator @jinja2 will expect  
> a Jinja2 view instead of a web2py view. Mind that you must create a  
> view file for @jinja2.
> Keep me posted on whether this works or you encounter any issue.  
> Example
>
> @jinja2
> def index(): return dict(hello='world')
>
> with FILE: yourapp/views/default/index.html BEGIN
> Hello {{ hello }}
> END
>
> should make "Hello world".
>
> Massimo
>
> P.S. I am ccing the list since others may be interested
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to