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

Yariv Sadan <>
Wed Jun 14 07:26:29 CEST 2006

> I would personally avoid any imperative / non-declarative
> construct in a template language.
> Tons of template languages exist for PHP, etc. so one should at
> least look at them and reuse ideas from them.

I actually think there's something to learn from Drupal, the popular
open source PHP CMS. Drupal's default template engine used to be
xtemplate, which had a basic template language, but at a recent
version, Drupal switched to PHP template by default. The reason, as I
recall, is that the Drupal developers realized they already 'had' a
template language: PHP.

Ruby on Rails also has a template engine that embeds Ruby code.

I think one should consider making an Erlang template engine. It would
look like current Yaws pages, but different. For instance, let's say
your controller had this code

get_users(A) ->
  [{person1, [{"name", "john"}, {age, 26}, {hobbies, [music, movies}]},
  {person2, [{"name", "lisa"}, {age, 27}, {city, "new york"}]}].

The template could look like

match({person1, Props} = Obj) ->
   props:get(hobbies, Props).

 match({person2, Props} = Obj) -> props:get(name, Props).

<%= length(Data) %> people

I'm not sure that this syntax is really optimal (I just came up with
it), but I think there's an advantage to using a turing complete
template laugnage with a short learning curve :)


More information about the erlang-questions mailing list