[Catalyst] Re: Action for index not 'index'?
Aristotle Pagaltzis
pagaltzis at gmx.de
Wed Mar 23 20:10:02 GMT 2011
* will trillich <will.trillich at serensoft.com> [2011-03-23 15:30]:
> What we do instead is, we call a function to add another link
> in our breadcrumb chain, so it's deliberate and we're
> completely in control:
That’s what I did too.
> sub add_breadcrumb {
> my ( $c, $path, $label ) = @_;
> my $bc = $c->stash->{breadcrumbs} ||= [];
> push @$bc, +{
> path => $path,
> label=> $label,
> };
> }
Mine looks like this:
sub breadcrumb {
my $c = shift;
my $label = shift;
my $uri;
$uri = $c->uri_for_action( @_ )
if @_;
push @$_, {
label => $label,
href => $uri.
} for $c->stash->{ breadcrumbs };
return $c;
}
Note that it takes the label as first argument.
This yields a few nice properties. You can set breadcrumbs as
pure labels without a link simply by passing just the label.
I use that option mainly on the final action of a chain. (The
code in the template also omits the `<a>` on the last breadcrumb
even if there is a link.)
And aside from the first argument it’ll work just like Catalyst’s
own `uri_for_action`.
So in a typical mid-chain action I get something like this:
sub base : PathPart('workspace') CaptureArgs(0) {
# ...
$c->breadcrumb( 'Workspace', '/workspace/list' );
}
sub item : PathPart('') CaptureArgs(1) {
# ...
$c->breadcrumb( $ws->name, '/workspace/view', [$ws->id] );
}
So the chain structure automatically yields the right choice and
sequence of breadcrumbs.
--
*AUTOLOAD=*_;sub _{s/::([^:]*)$/print$1,(",$\/"," ")[defined wantarray]/e;chop;$_}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>
More information about the Catalyst
mailing list