> You can save some typing by passing a Fun, e.g.
>
> controller:
>
> show(A, Id) ->
>   Artist = artist:find_id(Id),
>   {data, fun(Field) -> val_to_iolist(artist:Field(Artist)) end}.
>
> view:
>
> <%@ show(F) %>
> name: <% F(name) %><br/>
> age: <% F(age) %></br/>...

Cool.  I hadn't read that but that is a great suggestion.


> As you can see, this helps you defer declaring the list of field names
> until you actually use those fields in the view. With a bit of work
> you can make that fun generic and reuse it between components. I use
> this style Vimagi and I really like it.
>
> Going back to Colm's original suggestion, although I'm not sure that
> adding that kind of FOREACH construct would make ErlTL accessible to
> designers, I do agree that it would be nice to have a way of declaring
> "anonymous functions" in the body of ErlTL functions so you don't have
> to declare everything at the top level. Currently, ErlTL has syntax
> for module-level functions, but not for funs. Such syntax would make
> it possible to inline list comprehensions in a way that would
> sometimes make them more readable. For example, this is what you would
> do today:
>
> <%@ album(Name, Songs, Comments) %>
> Album: <% Name %>
> <table>
> <% [song(S) || S <- Songs %>
> </table>
> <% Comments %>
>
> <%@ song(S) %><tr><td><% S %></td></tr>
>
> The 'song' snipped is declared outside of where it is placed in the
> body of the page. It would be nice to be able to inline it such as in
>
> <%@ album(Name, Songs, Comments) %>
> Album: <% Name %>
> <table>
> <et:map S <- Songs>
>   <tr><td><% S %></td></tr>
>  </et:map>
> </table>
> <% Comments %>
>
> I'm not sure if that's the right syntax, but you get the idea.

I really like that idea.  It solves a large part of what I was trying
to get at with the FOREACH suggestion.

> I think this kind of feature would make ErlTL templates more
> Erlang-friendly. If you want to make your templates truly
> designer-friendly, you might be better off using a different, more
> "regular" template language altogether. ErlyWeb doesn't strictly
> require ErlTL and in fact it would be easy to support other template
> languages. If anyone wants to implement more template languages that
> are designer friendly (or the suggested inline map feature above),
> I'll be happy to add them to the framework.

Sure.  I don't think that is called for in this case, though.  If you
are open to adding a few extensions like the <et:map then I think that
would simplify the common case which is all I'm trying to address.

Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to