Playing with a new TemplateParser
Jonathan Hogg <[email protected]> Sat, 21 Jul 2001 23:10:54 +0100
| Newsgroups | gmane.comp.sysutils.ark.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I'm playing with an alternative TemplateParser. This is a very much
simpler version of what I had before - but in some ways more expressive.
I've ditched the whacky pseudo-python templating language (that I noticed
no-one was using anyway, in favour of just embedding some 'print'
statements) and have switched to using pure Python grammar.
You need to be a lot more careful about your spacing of course, but the
results look pretty cool. I've attached an example template below. I find
it helps to think of '%>...<%' bracketing bits of output rather than
'<%...%>' bracketing bits of code.
I'm looking for comments on whether I should jazz this up and replace the
one in Ark or not.
:-j
---------------------------
<%
import string
script = 'This'
status = 'test'
def check(colour):
if colour == "red":
%>Red's my favourite colour<%
else:
%>The colour was 100% <%=colour%>!<%
%>
<%= script %> is a <%= string.upper(status) %>:
<%
check('red')
%>
And this is another:
<%
check('green')
%>
Here's an interesting one, let's do something with a try...except block.
<%
try:
%>This will fail for sure: <%= broken_thing %><%
except:
%>Sure enough, the thing broke. But we caught it!
---------------------------
The result of running this is:
---------------------------
This is a TEST:
Red's my favourite colour
And this is another:
The colour was 100% green!
Here's an interesting one, let's do something with a try...except block.
Sure enough, the thing broke. But we caught it!
---------------------------
--
jonathan hogg, one good idea ltd, 131 queen margaret dr., glasgow g20 8pd
http://www.onegoodidea.com/ tel:+44-(0)7976-614338 fax:+44-(0)7970-537451