[Catalyst] Setting View

Jon catalyst at bytabok.com
Sun May 21 10:27:11 CEST 2006


On 5/20/06, Matt S Trout <dbix-class at trout.me.uk> wrote:
>
> Jon wrote:
> > Hi,
> >


[snip]

>
> > Is Catalyst-View-JSON-0.09 The Right Thing to use for json? First
> > release 04 Jan, and last release 10. Gives the impression of not being
> > an active and robust module that follows the Catalyst progress.
>
> It's not had another release because it already works and hasn't AFAIK
> had any bugs reported against it.
>
> I implemented a JSON-REST API recently using this and it worked perfectly.


Nice, I just got a bit worried it was yet another module someone thought
would be nice, started making and stoped making after getting tired of it.
Since it seems to be ready I'll go for it.

> It's often mentioned how simple it is to switch between HTML/XML/FOO by
> > using different views in Catalyst, but I haven't found documentation on
> > how the prefered way of picking template/language/template system. For
> > me (coming from Apache::CGI) I'd want to put it like this:
> >
> > 1 Set base name of template in Controller method, ie
> > $c->stash->{template} = 'foo/bar'
> > 2 At Root::end check cookies (and/or params) for language settings and
> > append '_lang'
> > 3 Still at Root:end check param 'output', 'format' or something similar
> > for what template system to use and forward to it.
>
> The code below would work fine; you could make it even simpler by using
>
> $c->stash->{view_type} = 'JSON'; # for example
>
> then in your end
>
> $c->forward($c->view($c->stash->{view_type}||'TT'));
>
>
> Hmm, I'm not sure I follow you there, where would you want the stash to
happend? I'd prefer the controllers not to know anything about the template
their data is used in (I'm pretty new to MVC so there might be something I
miss, or I might be overzealotish trying to learn how to do it The Right
Way).

After some thinking while re-reading the stash you put there I'd change my
original three steps to be:
1. Set template type in begin where I untaint all paramters
($c->stash->{view_type} or something)
2. Set template name in controller getting called by URI
3. Set language in the END by appending _$language depinging on member
setting/cookie/param
4. Add .type ($template .= '.tt' if $view_type = 'TT' ) in end depending of
template system so I can have index.tt, index.json, index_se.tt without
changing anything

Is this remotely what you mean or am I on thin ice in deep waters?

Thanks for the quick reply!
/jon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060521/8a5713ef/attachment.htm 


More information about the Catalyst mailing list