Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Template-engine

Reply
Thread Tools

Template-engine

 
 
=?ISO-8859-1?Q?Jan-Erik_Meyer-L=FCtgens?=
Guest
Posts: n/a
 
      11-05-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', '(E-Mail Removed)'),
Client('Keskinen', 'Miika', '(E-Mail Removed)'),
]

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

--
Jan-Erik

 
Reply With Quote
 
 
 
 
Miika Keskinen
Guest
Posts: n/a
 
      11-05-2003
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)

--
Miika
 
Reply With Quote
 
 
 
 
Thomas Weholt
Guest
Posts: n/a
 
      11-05-2003
Or you can try SimpleTal/es, available at http://www.owlfish.com

Thomas

"Miika Keskinen" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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)
>
> --
> Miika



 
Reply With Quote
 
Thomas Guettler
Guest
Posts: n/a
 
      11-05-2003
Am Wed, 05 Nov 2003 14:24:00 +0100 schrieb Jan-Erik Meyer-Lütgens:

> 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/


try python:

def foo(self):
ret=[]
ret.append(self.header())
ret.append("""
Time is too short to rewrite parsers <br>
...
""")
ret.append(self.footer())
return ''.join(ret)

thomas

 
Reply With Quote
 
Miika Keskinen
Guest
Posts: n/a
 
      11-05-2003
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

> Or you can try SimpleTal/es, available at http://www.owlfish.com
>
> Thomas
>
> "Miika Keskinen" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> 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.


 
Reply With Quote
 
Erik Max Francis
Guest
Posts: n/a
 
      11-05-2003
Miika Keskinen wrote:

> 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/

--
Erik Max Francis && http://www.velocityreviews.com/forums/(E-Mail Removed) && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ I just don't know why they're shooting at us.
\__/ Capt. Benjamin "Hawkeye" Pierce
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments