template language patch

4 views
Skip to first unread message

DenesL

unread,
Dec 30, 2008, 10:05:18 PM12/30/08
to web2py Web Framework
Massimo,
I sent you a patch proposal to template.py that allows python code to
be included in views without the use of pass statements by following a
few easy rules.
Please have a look and let me know of any comments.

mdipierro

unread,
Dec 31, 2008, 5:12:12 AM12/31/08
to web2py Web Framework
Hi Denes,

got it and will look at it asap. Would you mind posting also on the
list so we can get pros/cons?

Massimo

DenesL

unread,
Dec 31, 2008, 11:23:47 AM12/31/08
to web2py Web Framework
I can't upload the patch file to the group but I can describe what it
does.

The patch allows python code to be re-used with a simple copy/paste
operation, which can otherwise get very frustrating when you have to
split it up to insert the double braces and "pass" at appropriate
locations to make it work in a view.

RULES: the code has to start with {{! and end with }} as the first
chars in a separate line,
the = is replaced by response.write only if it is the first non-blank
char in a line,
the original indentation is kept.

Example:
...
<td>{{!v=inp[f]
if hasattr(v,'xml'):
=v.xml()
else:
=v
a='test'
=a
}}</td>
</tr>
...

would end up as:
...
v=inp[f]
if hasattr(v,'xml'):
response.write(v.xml())
else:
response.write(v)
a='test'
response.write(a)
response.write('</td>\n</tr>',escape=False)
...

There is an obvious cost of parsing two additional regex rules.
Reply all
Reply to author
Forward
0 new messages