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

Yariv Sadan yarivvv@REDACTED
Wed Jun 14 15:53:01 CEST 2006

> Lot's of yaws apps have been built using the ?TXT macro
> from jungerl. Easy.

Claes, I assume it shouldn't be too difficult to add to Yaws another
rendering function, which would be used such as

yaws_api:render("template1.tpl", TemplateData).

where template1.tpl has such code:

out(Data) ->
  Person1 = data:get(person1, Data),
  %% do something with Person1
   Result = io_lib:format("~w", [Person1]),

   %% modify props
   NewData = data:add({person2, [{name, "bob"}]}, Data),

    %% return result
   {Result, NewData}.

<%! this is a comment, won't be rendered %>

<%! syntactic sugar for implicitly writing 'out(Data) ->...{Result} ' %>
<%= data:get(person2, Data). %>

<%= yaws_api:render("footer.tpl", {year) %>

The major change is to modify out(A) to accept the Data parameter
rather than today's Arg, and to make it return either {Result} or a
{Result, NewData} tuple. NewData, if exists, will be passed to
subsequent out(Data) calls.

With this feature, it will be quite easy to add a controller that
takes a URL, calls a function and matches the result with a template

What do you think?


More information about the erlang-questions mailing list