[Catalyst] Picking template type based on input

Jon mailinglists jon.mlist at gmail.com
Fri Mar 26 16:31:29 GMT 2010


On Fri, Mar 26, 2010 at 1:50 PM, Tomas Doran <bobtfish at bobtfish.net> wrote:
> Jon mailinglists wrote:
>>
>> Hi all,
>> [snip]
>
> How is generating JSON in template toolkit not 100% insane?
>
> Please use something like Catalyst::View::JSON instead?
>

To be honest I haven't tried it but seeing you're involved in it I
understand that stance :)

I don't think Catalyst::View::JSON would help me though since I need
to send "YUI JSON", ie:
MyNamespace.callback({"ResultSet":{

Which would force me to do make changes in the result anyway, and a
few loops in a tt2 file isn't that much of a problem.

>> but it feels "wrong" to put it in the Root controller rather than the
>> view. Is this really the place where I'm supposed to have that kind
>> of logic? Would that also be the place if I want to add pdf out to
>> pick another View to forward to?
>
> Yes.
>
> The controller asks the model for some data, and then chooses how to present
> that data (whilst the view actually handles the presentation details.
>
> In the example of a PDF, you'd set $c->stash('current_view' => 'PDF');
>

When you say "and then chooses how to present that data" I take it's
in a very limited way it gets to choose? I mean the templates tend to
(at least in my case) have a few loops and if/else in them.

To me it makes more for the Controller to ask the Model for data, do
logic and put it in the stash and then tell the View. "Here's your
data, apply your limited logic to it and render a nice output."

Regarding PDF/XML/JSON/HTML/text/whatever as output I would very much
prefer the View to make that decision. IE a View super module seing
the parameters/accept and telling the right sub View to deal with it.

That doesn't seems to be the general idea though?



More information about the Catalyst mailing list