[Catalyst] Setting View

Jon catalyst at bytabok.com
Sat May 20 11:24:02 CEST 2006


I'm doing a small project where I use (and learn) Catalyst. I've decided to
use some Ajax in it, MochiKit, and I want JSON templates for that. Currently
I'm using TT for all templates but browsing CPAN I saw there's a View::JSON
which seems better to use. Now, I have two questions regarding this:

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 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} =
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.

That is something like:


sub bar : Local {
  my ($self, $c) = @_;
  $c->stash->{template} = 'foo/bar';


sub end : Private {
  my ($self, $c) = @_;
  $c->stash->{template} ||= 'index';
  if ($c->req->params->{language} && language_exists($self, $c))
        $c->stash->{template} .= '_'.$c->req->params->{language};
  my $view = 'MyApp::View::TT';
  if ($c->req->params->{output} eq 'json')
     $view = 'MyApp::View::JSON';
  # elsif ...
  $c->forward($view) unless $c->res->output;

Thanks in advance

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060520/e1c6bbca/attachment.htm 

More information about the Catalyst mailing list