On Nov 16, 6:24 pm, David King <[EMAIL PROTECTED]> wrote:
> > - A while ago somebody asked a similar question and Bryan Fink
> > suggested returning a tuple of the form {title, Title} from the view
> > function, and then later picking up this tuple in the
> > html_container_controller and using its value to set the <title> tag.
>
> That does only take into account <title>s, and not any other
> metadata. And doesn't using erltl preclude returning something useful
> from a view function other than the data itself? And then the
> component receiving the rendered page would have to walk the
> resultant IOlist looking for it, rather than being able to pattern-
> match it. That just seems very brittle.
Yeah, it is a bit brittle. But, some tips:
1. If you need to return several things for the container to find,
just use more tuples. I have {title, X}, {head, X}, {onload, X}, etc.
2. ErlTl works just fine with this. The code looks like:
<%@ index(Beer) %>
<% {title, ["BeerRiot - ", beer:name(Beer)]} %>
<% {head, <<"<script>...</script>">>} %>
3. My container controller picks each of these piece out using two
rules:
a. all such tuples must be at the start of the rendered data
b. all such tuples must be in a defined order
So, the container code looks roughly like:
index(Data) ->
case Data of
[{title, Title} | TData] -> ok;
TData -> Title = "BeerRiot"
end,
case TData of
[{head, Head} | HData] -> ok;
HData -> Head = <<>>
end
...
{data, {Title, Head, OtherData}}.
I have to play a few more tricks, though, to account for newlines in
the rendered Data list. That could be fixed by moving the ErlTl
statements all to one line, but it didn't seem important enough to
worry about.
So, that restricts using these tuples to the "top level" component
view, but it has worked pretty well for me so far.
The idea of adding a {meta, X} tuple to the list of things a
controller can return sounds interesting, but since this stuff is more
on the view side, it also seems a little out of place. Not to say
that my hack isn't further out of place, of course. ;)
-Bryan
P.S. If you think the idea of a beer_controller is great, you'll love
that I also have a beer_container_controller, but only because I
couldn't decide among bottle_controller, can_controller, and
keg_controller. :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to erlyweb@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---