Erlang Mailing Lists

Author Message

<  Erlyweb mailing list  ~  Rendering AJAX responses without layout

Guest
Posted: Wed Sep 19, 2007 5:44 pm Reply with quote
Guest
When serving Ajax requests via erlyweb, I just want to get the
rendered content of a component, without the surrounding template. Is
there an erlyweb way to do that ?

I have currently implemented a layout/1 function in all my controllers
which returns a boolean,
and this is my hook/1 function definition in the AppController:

hook(A) ->
{phased, {ewc, A},
fun(Ewc, Data) ->
{ewc,Controller,View, Function,_} = Ewc,
case Controller:layout(Function) of
true ->
{ewc, html_container, index, [A, {data, Data}]};
false ->
{ewc, A}
end
end}.

Is there a better way to do this?


--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Wed Sep 19, 2007 6:17 pm Reply with quote
Guest
On Sep 19, 1:44 pm, srk <reach...@gmail.com> wrote:
> When serving Ajax requests via erlyweb, I just want to get the
> rendered content of a component, without the surrounding template. Is
> there an erlyweb way to do that ?
>
> I have currently implemented a layout/1 function in all my controllers
> which returns a boolean,
> and this is my hook/1 function definition in the AppController:
>
> hook(A) ->
> {phased, {ewc, A},
> fun(Ewc, Data) ->
> {ewc,Controller,View, Function,_} = Ewc,
> case Controller:layout(Function) of
> true ->
> {ewc, html_container, index, [A, {data, Data}]};
> false ->
> {ewc, A}
> end
> end}.
>
> Is there a better way to do this?

I don't know about "better", but I do use a couple of other methods
for things like this.

The first is very similar to yours - in hook/1, check the request path
for certain pieces, and return just an ewc tuple instead of a phased
tuple if I don't want the result wrapped in the normal container.

The second feels a little more hackish. All view functions up to your
container can return things other than iolists. So, for example, you
could drop a "no_container" atom in the list your AJAX view function
returns, then have your container rendering look for that atom in the
data it receives. I'm using this to shove things like titles into my
html's head section (<% {title, "Page Title"} %> at the start of a
view function means my container can check for [{title, Title} |
Rendered]). This will break, or at least become much more
complicated, if you're doing lots of other nested rendering.

So, yeah, the short answer was, "No, I don't think there is a better
way."

-Bryan


--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
dmitriid
Posted: Thu Sep 20, 2007 6:55 am Reply with quote
User Joined: 17 Aug 2006 Posts: 213
Bryan Fink wrote:
Quote:
On Sep 19, 1:44 pm, srk <reach...@gmail.com> (reach...@gmail.com) wrote: [/code]
Quote:
When serving Ajax requests via erlyweb, I just want to get the rendered content of a component, without the surrounding template. Is there an erlyweb way to do that ? I have currently implemented a layout/1 function in all my controllers which returns a boolean, and this is my hook/1 function definition in the AppController: hook(A) -> {phased, {ewc, A}, fun(Ewc, Data) -> {ewc,Controller,View, Function,_} = Ewc, case Controller:layout(Function) of true -> {ewc, html_container, index, [A, {data, Data}]}; false -> {ewc, A} end end}. Is there a better way to do this? [/code]
I don't know about "better", but I do use a couple of other methods for things like this. The first is very similar to yours - in hook/1, check the request path for certain pieces, and return just an ewc tuple instead of a phased tuple if I don't want the result wrapped in the normal container. [/code]
Most AJAX implementations set the HTTP_X_REQUESTED_WITH header to "XmlHTTPRequest". So no need to check paths, you can only check for this header


--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Thu Sep 20, 2007 8:17 am Reply with quote
Guest
I use something similar to the approach you showed. I don't think
there's a much better way of doing it, short of maybe using request
headers as Dimitrii suggested.

Yariv

On 9/19/07, srk <reachsrk@gmail.com> wrote:
>
> When serving Ajax requests via erlyweb, I just want to get the
> rendered content of a component, without the surrounding template. Is
> there an erlyweb way to do that ?
>
> I have currently implemented a layout/1 function in all my controllers
> which returns a boolean,
> and this is my hook/1 function definition in the AppController:
>
> hook(A) ->
> {phased, {ewc, A},
> fun(Ewc, Data) ->
> {ewc,Controller,View, Function,_} = Ewc,
> case Controller:layout(Function) of
> true ->
> {ewc, html_container, index, [A, {data, Data}]};
> false ->
> {ewc, A}
> end
> end}.
>
> Is there a better way to do this?
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Sep 21, 2007 4:27 am Reply with quote
Guest
Using request headers is useful if it is sure that no Ajax requests require a layout, but i think essentially, the decision has to be made by the controller function whether it needs a layout or not.
I kind of prefer the Rails way of doing this which is to return the choice of the layout from the action on the controller
i.e
Guest
Posted: Fri Sep 21, 2007 1:11 pm Reply with quote
Guest
On Sep 21, 12:27 am, "Karthik S R" <reach...@gmail.com> wrote:
> Using request headers is useful if it is sure that no Ajax requests require
> a layout, but i think essentially, the decision has to be made by the
> controller function whether it needs a layout or not.
> I kind of prefer the Rails way of doing this which is to return the choice
> of the layout from the action on the controller
> i.e
> render :action => 'some_action', :layout => false
>
> Maybe something like this should be implemented in erlyweb too... are there
> any downsides to this approach?
>
> srk.

No need to implement anything extra in erlyweb. The second method I
gave in my earlier post (returning something easily recognizable, like
an atom or a tuple, from your view method, and watching for it in your
layout component) does exactly this already.

Unless I'm mistaken, or Yariv says that's a really bad idea...

-Bryan


--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
Guest
Posted: Fri Sep 21, 2007 5:27 pm Reply with quote
Guest
On 9/21/07, Bryan Fink <bryan.fink@gmail.com> wrote:
>
> On Sep 21, 12:27 am, "Karthik S R" <reach...@gmail.com> wrote:
> > Using request headers is useful if it is sure that no Ajax requests require
> > a layout, but i think essentially, the decision has to be made by the
> > controller function whether it needs a layout or not.
> > I kind of prefer the Rails way of doing this which is to return the choice
> > of the layout from the action on the controller
> > i.e
> > render :action => 'some_action', :layout => false
> >
> > Maybe something like this should be implemented in erlyweb too... are there
> > any downsides to this approach?
> >
> > srk.
>
> No need to implement anything extra in erlyweb. The second method I
> gave in my earlier post (returning something easily recognizable, like
> an atom or a tuple, from your view method, and watching for it in your
> layout component) does exactly this already.
>
> Unless I'm mistaken, or Yariv says that's a really bad idea...
>
> -Bryan
>

I haven't tried your approach, but I don't see why it shouldn't work.
It looks like a good way of passing dynamic information to the
container from the controller function. It's just not obvious that it
could be done, so maybe it needs to be added to the documentation.

Props for coming up with it Smile

Yariv

--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
dmitriid
Posted: Sat Sep 22, 2007 12:16 pm Reply with quote
User Joined: 17 Aug 2006 Posts: 213
> I haven't tried your approach, but I don't see why it shouldn't work.
> It looks like a good way of passing dynamic information to the
> container from the controller function. It's just not obvious that it
> could be done, so maybe it needs to be added to the documentation.
>
>
Slight offtopic on documentation. I wonder if it would be better to turn
docs into a wiki. This way users can also contribute to the
documentation especially in the more obscure details.

Only registered users, of course.

--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message
Guest
Posted: Sat Sep 22, 2007 5:00 pm Reply with quote
Guest
I want to start a wiki but I don't know how to integrate the existing
docs into it. I find edoc convenient for documenting APIs and I don't
want to split the documentation site into both a wiki and an edoc
section. Any ideas?

> >
> >
> Slight offtopic on documentation. I wonder if it would be better to turn
> docs into a wiki. This way users can also contribute to the
> documentation especially in the more obscure details.
>
> Only registered users, of course.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
dmitriid
Posted: Mon Sep 24, 2007 6:21 am Reply with quote
User Joined: 17 Aug 2006 Posts: 213
Yariv Sadan wrote:
> I want to start a wiki but I don't know how to integrate the existing
> docs into it. I find edoc convenient for documenting APIs and I don't
> want to split the documentation site into both a wiki and an edoc
> section. Any ideas?
>
>
Hmmm... Well, most wikis allow insertion of pure HTML into their pages.
I guess something like edoc:get_doc/2 could be used to extract
documentation and then probably post'ed via inets to a wiki.

I dunno Smile

--~--~---------~--~----~------------~-------~--~----~
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 erlyweb-unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Post recived from mailinglist
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum