Template-engine

Jan-Erik Meyer-Lütgens python at meyer-luetgens.de
Wed Nov 5 08:24:00 EST 2003


Miika Keskinen wrote:
> Hi all
> 
> I was in need for a simple template engine (like PEAR::IT.php) and didn't
> find any suitable. Yes, there is many templating engines available but
> most are far too complex or does implement some additional features in
> their syntax.
> 
Try Cheetah: http://www.cheetahtemplate.org/

<HTML>
<HEAD><TITLE>$title</TITLE></HEAD>
<BODY>

<TABLE>
#for $client in $clients
<TR>
<TD>$client.surname, $client.firstname</TD>
<TD><A HREF="mailto:$client.email">$client.email</A></TD>
</TR>
#end for
</TABLE>

</BODY>
</HTML>

------------------------------------------------------
from Cheetah.Template import Template

class Client:
   def __init__(self, surname, firstname, email)
     self.surname = surname
     self.firstname = firstname
     self.email = email

clients = [
   Client('Meyer-Lütgens', 'Jan-Erik', 'un at kown.de'),
   Client('Keskinen', 'Miika', 'un at known.fi'),
]

tpl = Template(file='path_to_tpl_file')
tpl.title = 'The Title'
tpl.clients = clients
print tpl

-- 
Jan-Erik





More information about the Python-list mailing list