RFC: template engine [ was: Re: Implementing tables - advice wanted ]

Gaspar Chilingarov nm@REDACTED
Tue Jun 13 23:23:03 CEST 2006


Hello all!

Post directed mainly to ke han, but all other list members are welcome
-- You have mentioned html template engine for erlang - what kind of
features do you like in there ?

For current moment I got some simple engine which provides following
templating commands -

<%TRANSLATE atom%>  - generate string, calling some translation function
(to make multilangual sites)

<%FOREACH keyname%> - <%/FOREACH%> - take element keyname from proplist
(which should have list value) and iterate inner part of FOREACH loop
for each element in that list.
<%WITH keyname%> <%/WITH%>- just go one level deeper - fetch one element
from proplist and execute inner template with it

<%PUT keyname%> - just put element of proplist into current position.
<%PUTVALUE%> - if we are in a leaf node - put it's value into current
position - ether string or integer.

so
if you have template
<%FOREACH args%><%PUTVALUE%> <%/FOREACH%>

and we feed templating function with
{struct, [
	{args, {array, ["Hello", "world", "!"]} }
]}
data we will receive "Hello world ! " string.

this approach - added with if/ifdef/else commands allows
create templates which are totally separate from programming language
and are driven only by data which is fed to template interpreted.

it somehow resembles XSLT, but much more simple to allow HTML designers
easily use it and put into pages without disturbing programmer too much.

second idea with such markup is that there is translator from such
markup to JSON notation, and there is JS template renderer, which could
be run on client machine - thus allowing passing from server not
rendered template, but parsed template and data -- JS copes well even on
slow machines with datasets about up to 1000 elements  - like 10x100
table - which is practically enough for most tasks.


I would like to listen any suggestions on templating solution, which you
would like to see - even too fantastic or futuristic -- because it's
always possible to find something reasonable and practical there.


Looking forward for answers :)

-- 
Gaspar Chilingarov

System Administrator,
Network security consulting

t +37493 419763 (mob)
i 63174784
e nm@REDACTED



More information about the erlang-questions mailing list