[Catalyst] A View that may include elements optionally
returnedfrom other funcs
Joe Landman
landman at scalableinformatics.com
Wed Apr 25 15:41:12 GMT 2007
On Wed, 25 Apr 2007 11:58:02 +0100, Carl Johnstone wrote
> > Ugh... Assume that the view gets everything from controller. Then this
> > controller is the thing that should gather everything together before
> > shipping it to the view. Let the template decide the form, let the
> > controller decide the content.
>
> That's fair enough, but say you've got 20 possible page elements of
> which typically 5 or 6 are included in the final page. Would you
> still suggest that the Controller should initialize any data for all
> 20 elements onto the stash?
Absolutely not. On the contrary, I specifically indicated that blank sections
should be left undef. If the stash for that section is undef, then the view
can completely (programmatically) skip that section.
>
> What if some of those elements are relatively expensive to generate?
See above, and please refer to my original note.
>
> What Steve wants is some way of being able to decide in the View
> which of those elements are included and load them accordingly.
... and this should be done at the controller level is what I am saying. You
can even have your controller select a particular view based upon the
available data if you wish. Or have a single view template handle everything
(and only render bits that are defined, which is what I had indicated, this
way you do not have to construct everything, just what you need).
>
> The best solution I can come up with is passing coderefs into your
> view which can then be run to retrieve the data would something like
> this work?
>
> $c->stash->{'get_most_popular'} = sub {
> return $c->model('DB')->some_expensive_db_op();
> };
Maybe I am confused about MVC, but wouldn't you want the view to decide how to
present what is sent to it by the controller, and hence have the controller
handle this?
>
> Carl
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
--
Scalable Informatics LLC
http://www.scalableinformatics.com
phone: +1 734 786 8423
More information about the Catalyst
mailing list