473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Template-engine

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
Jul 18 '05 #1
5 2250
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', 'u*@kown.de'),
Client('Keskinen', 'Miika', 'u*@known.fi'),
]

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

--
Jan-Erik

Jul 18 '05 #2
Or you can try SimpleTal/es, available at http://www.owlfish.com

Thomas

"Miika Keskinen" <mi************@utu.fi> wrote in message
news:pa****************************@utu.fi...
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

Jul 18 '05 #3
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

Jul 18 '05 #4
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" <mi************@utu.fi> wrote in message
news:pa****************************@utu.fi...
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.


Jul 18 '05 #5
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 && ma*@alcyone.com && 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
Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Oplec | last post by:
Hi, I'm learning C++ as a hobby using The C++ Programming Language : Special Edition by Bjarne Stroustrup. I'm working on chpater 13 exercises that deal with templates. Exercise 13.9 asks for me...
31
by: nikola | last post by:
Hi all, I was working with a simple function template to find the min of two values. But since I would like the two values to be different (type) I dont know what kind of value (type) it will...
5
by: Gianni Mariani | last post by:
The spirit of this arguably pointless exercise, is that the numeric_limits<T> class could be replaced with a totally generic template of compile-time, template computed constants. The problem is...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
2
by: Alfonso Morra | last post by:
I have a class declared as ff: class __declspec(dllexport) A { public: A() ; A(const A&) A& operator=(const A&) ; ~A() ; void doThis(void) ;
19
by: aaragon | last post by:
Hi everyone. A very simple question. I would like to know what is better in terms of performance. I want to use a simple function to obtain the minimum of two values. One way could be using a...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
45
by: charles.lobo | last post by:
Hi, I have recently begun using templates in C++ and have found it to be quite useful. However, hearing stories of code bloat and assorted problems I decided to write a couple of small programs...
9
by: Leo jay | last post by:
i'd like to implement a class template to convert binary numbers to decimal at compile time. and my test cases are: BOOST_STATIC_ASSERT((bin<1111,1111,1111,1111>::value == 65535));...
2
by: Gary Nastrasio | last post by:
I'm currently reading Andrei Alexandrescu's book "Modern C++ Design" and I'm a bit confused by one bit of template syntax in chapter 1. Here is a code example: template <class CreationPolicy>...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.