Template-engine

  • Thread starter =?ISO-8859-1?Q?Jan-Erik_Meyer-L=FCtgens?=
  • Start date
?

=?ISO-8859-1?Q?Jan-Erik_Meyer-L=FCtgens?=

Miika said:
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', '(e-mail address removed)'),
Client('Keskinen', 'Miika', '(e-mail address removed)'),
]

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

Miika Keskinen

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.

So I created following and I'm asking comments - and yes I know there is
couple not so pythonistic sides in code. Most of all accessing inner dict
B straight. This is however first working version (started it hour ago)
and I'm asking if any of you have something in mind that could help me
making that better.

This engine is non only for html ( in fact I don't use it for html but
email-templates and some configuration-templates ).

the beast can be found from http://users.utu.fi/mikrke/index.html
(includes example how to use it)
 
M

Miika Keskinen

On Wed, 05 Nov 2003 16:48:40 +0100, Thomas Weholt wrote:

Well. These all look very promising. At my situation (I have lot's of
templates originally written for php/IT) amount of work needed for using
them would be too much. (of course one could write down some regexp-beasts
or parsers to automatically convert them - I'm not that one :)

So currently I will stick on my implementation and for future projects
it might well be showtime for chetah/simpleTal.

btw. If my work is not useful to any other it might server well as
newbie-example how to use re.sub :)
 
E

Erik Max Francis

Miika said:
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.

EmPy has a lot of additional features, but they're all optional. Basic
use of EmPy for templating is as lightweight, if not more, as your
approach:

http://www.alcyone.com/software/empy/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top