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

ke han ke.han@REDACTED
Wed Jun 14 20:28:30 CEST 2006

On Jun 15, 2006, at 1:57 AM, Yariv Sadan wrote:

> Hi,
>> Indeed, these four characteristics seem to be all we need and is in
>> line with mine and others' intuition that a template engine should
>> _not_ be a Turing complete language.
> I would like to bring up one more point in favor of using Erlang as a
> template language: ehtml. With an Erlang template language, you could
> write code such as
> <%=
>       {ehtml, {table, [], {
>            lists:foldl(fun(E, A) ->
>                [{tr, [], {td, [{width, 20}], E#person.name}} | A]
>         end, [], dict:get(people, Data))}
>        }
>      },
> %>

according to StringTemplate syntax, your example can be written more  
clearly, IMO:


where row() is defined as:
<tr><rd width=20>$attr.name$</td></tr>

- or -  if you feel like putting it together as one:

$people: {
	<tr><td width=20>$attr.name$</td></tr>

I think if you read the pdf referred in this thread, you can see the  
rational for not using erlang as the template language but in favor  
of using erlang for all the behavior needed elsewhere such as the  
controllers, models, and renderers.  In other words, "if  
StringTemplate can't easily help you construct your view, then you  
shouldn't be coding that behavior in the view".

thanks, ke han

> in the template file. I think there's little doubt that this code does
> not belong in the controller, and that an ehtml tuple generated with
> pure Erlang is quite elegant.
> My 2c.
> Regards,
> Yariv

More information about the erlang-questions mailing list