Hallo,
Shayne ONeill hat gesagt: // Shayne ONeill wrote:
>
> 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>
If you use "templates" like:
<div class="raraa">%(name)s</div>
you can even omit the "for k,v ..." loop altogether and just write:
tpl = f.read()
replacelist["name"] = "doobeedoo"
tpl = tpl % replacelist
And Python 2.4 has an even nicer syntax for this.
However "plain ol' html" is not what I would consider a real template
language, as that would include control structures like for-loops etc.
One might argue, that Python code can be a template language then
itself, though. PSP and Kid work this way behind the curtain anyway.
Ciao
--
Frank Barknecht _ ______footils.org__
-------------------------------------------------------
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
[email protected]
https://lists.sourceforge.net/lists/listinfo/webware-discuss