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

Christian S chsu79@REDACTED
Wed Jun 14 11:51:20 CEST 2006


On 6/14/06, Yariv Sadan <yarivvv@REDACTED> wrote:
> >
> > 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.
>
[snip]
>
> 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 :)

I would have to second this. I have suffered template languages[*]
that are made to be small and simple ("only the things you're ever
going to need (TM)"), only to reach a point where they are
insufficient.  *Erlang is succinct and readable enough to be the
language to be used, and it is very complete.*

What I miss the most in yaws is a way to call erlang code using less typing.
<? mod:fun(Arg,...) ?>, or similar would be nice. Especially since the
<erl> tag sports a module attribute, allowing you to name the created
module that contains the code . Then one can locate all the reused
components in the same yaws-file they're used in.

I'm imagining things like

<h2><? i18n("Text in your language!") ?></h2>
<p>
<? i18n("Enjoy this refreshing example in your preferred language.") ?>
</p>

That is, if yaws had an i18n framework at all, and i18n was imported
from yaws_api.

<erl module="shop_product_html">
producttable(Category) ->
  %% Lookup Category products and
  %% return a ehtml table from the result.
...
</erl>

<h1>Buy junk!</h1>
<? shop_product_html:producttable(junk) ?>

[*] So far: Apache Velocity and XSLT (hardly that small though)



More information about the erlang-questions mailing list