ERRATA: Try this instead.
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, FileSystemLoaderenv = Environment(loader=FileSystemLoader(os.path.join(request.folder,'views',request.controller))template = env.get_template(response.view)return template.render(**d).encode('utf8')return _jinja2Those 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@jinja2def index(): return dict(hello='world')with FILE: yourapp/views/default/index.html BEGINHello {{ hello }}ENDshould make "Hello world".MassimoP.S. I am ccing the list since others may be interested
Most I agreed with Massimo. In Italo Maia email, he said he don't like
python code in template, but I like. Pure Python code is not beautiful
and it's not pythonic? You'll need to learn another template language
when you can use Python code in template. And you can even get all
powerful of Python. That's a great thing. Many template systems
support python code, except django one.
And rencently I'm working on making web2py template supports block tag
just like django. Say you have a parent template, looks like:
This base.html:
<html>
<head>
<title>{{block title}}Untitled{{end}}</title>
</head>
<body>
{{block main}}{{end}}
</body>
</head>
Here I defined two block title and main.
This is child template -- index.html:
{{extend "base.html"}}
{{block main}}<h1>Hello, Uliweb</h1>{{end}}
I defined main block, so when you render index.html, this main block
will replace the one defined in base.html. Because there is no title
block defined in index.html, so the title block defined in base.html
will be remained.
But use block support will break the {{include}} usage.
I'm using this new template module in my project uliweb. And the
module is in http://code.google.com/p/uliweb/source/browse/trunk/uliweb/core/template.py.
And I also made other changes, for example: parse_template will be
template_file, and the parameters are also different. But the syntax
of template tags are similar.
Maybe it's useful for someone.
--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: http://uliwebproject.appspot.com
My Blog: (new)http://http://hi.baidu.com/limodou
(old)http://www.donews.net/limodou