[Catalyst] reusable view components
Oleg Pronin
syber.rus at gmail.com
Thu May 17 20:13:34 GMT 2007
You can use this technique for simple forwarding to private action and
including its result template (to use with template-toolkit):
I defined a dynamic filter:
iforward =3D> [
sub {
my ($context, $c, $args) =3D @_;
return sub {
my $path =3D shift; #this is an action uri (for example,
'/schema/list').
my $tpl =3D $c->stash->{template}; #save template that =
had
been processed before
$c->forward($path); #call action
my $inc =3D $c->stash->{template}; #save action template
$c->stash->{template} =3D $tpl; #restore original templ=
ate
return $context->include(
$inc,
($args && ref $args eq 'HASH') ?
{%{$c->stash}, %{$args}} : #need to
update template toolkit's stash
$c->stash
); #return template processing result back to parent
template
};
}, 1
],
Usage of this is simple (in template):
Schemas list: <br />
[% '/schema/list' | iforward(c, additional =3D> 'args') %]
You could use something like that for mason.
P.S. We cannot use something simple like this:
[%CALL c.forward('...') %][%INCLUDE its_template%]
because template toolkit's stash is not changed when catalyst's stash is
change after the start of processing parent template.
2007/5/17, John Goulah <jgoulah at gmail.com>:
>
> Theres probably not one specific answer for this, but I was curious on
> peoples opinion. I'm basically trying to figure out what is the best way=
to
> create componentized views, such as Mason components allows you do reuse
> pieces of the page that are cachable. Would this basically be done on the
> template level pulling in pieces of various smaller templates into a bigg=
er
> wrapper like template, and forwarding (or perhaps chaining) within the
> controller to gather the data that gets passed into it? What are peoples
> thoughts on the best way to reuse as many parts of the page as possible w=
hen
> certain pieces are used on many pages within the app?
>
>
> Thanks!
> John
>
> _______________________________________________
> 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/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070517/50774=
2fa/attachment.htm
More information about the Catalyst
mailing list