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

Yariv Sadan yarivvv@REDACTED
Wed Jun 14 06:50:45 CEST 2006

On 6/13/06, Gaspar Chilingarov <nm@REDACTED> wrote:
> 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)

I would omit this from the template language to keep the language as
simple as possible. I think it's better to let the controller feed the
template with the correct strings.

> <%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.

I think you should consider using dicts rather than property lists,
because the lists can get quite long and inefficient.

> <%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
> 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.

> 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.

Interesting idea... I suggest you take a look at the RJS feature in
Ruby on Rails (http://api.rubyonrails.org/, under 'ActionView' and
'ActionView::Helpers::PrototypeHelper::JavaScriptGenerator'). RJS does
much more than just render text in the browser as it provides a set of
commonly used AJAX effects. Here's the example from the documentation:

 page.replace_html  'sidebar', :partial => 'sidebar'
 page.remove        "person-#{@person.id}"
 page.visual_effect :highlight, 'user-list'

These effects could be described as Erlang tuples, and the Javascript
generator would translate them into Javascript on the fly.

Just an idea, probably for v2 :)

> 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.

I think it's important to have some sort of an 'include' tag so you
can include templates from other templates.

<% include  "header" %>
<% include "footer" %>

and *please* don't make everything uppercase!

Keep us posted on your progress. :)


More information about the erlang-questions mailing list