Template engine in 6 lines :)

f =open('/templatedir/' + name, 'r')
template = f.read()
f.close()
for k,v replacelist():
      template = template.replace(str(k),str(v))
print template

You start with a template file which is plain ol' html with lines like
<div class="raraa">{name}</div>

you fill a list of replacements like follows;-
replacelist['{name}'] = 'John brown'

then run the above code and blammo. Instant templates.

This is of course why I somewhat adore python. :)

--
Shayne O'Neill..   trådkrämare
http://perth.indymedia.org
"I trust God speaks through me. Without that, I couldnt do my job."
--George W Bush.
http://atheism.about.com/b/a/099745.htm


On Fri, 31 Dec 2004, Tom Schwaller wrote:

> Has anybody used Webware together with the Kid Template language
> (which is based on ElementTree using concepts from XSLT, TAL and
> PHP in a very nice and simple mix, which I liked immediately).
>
> http://splice.sourceforge.net/kid/
>
> I know there are so many different template langauages
> and concepts around
>
> http://www.python.org/cgi-bin/moinmoin/WebProgramming
> http://wact.sourceforge.net/index.php/TemplateView
>
> but what I like about Kid is it's somewhat more Pythonic flavor
> than others.
>
> agree, disagree?
>
> Tom
>
>
>
> -------------------------------------------------------
> The SF.Net email is sponsored by: Beat the post-holiday blues
> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> _______________________________________________
> Webware-discuss mailing list
> Webware-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/webware-discuss
>


-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Webware-discuss mailing list
Webware-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to