[Catalyst] Bread crumb
Jason Kohles
email at jasonkohles.com
Tue Feb 6 14:33:36 GMT 2007
On Feb 6, 2007, at 5:26 AM, Gert Burger wrote:
> Hi
>
> Can someone who has implemented "bread crumbs" using catalyst
> please share their methods/problems etc. I need to implement it but
> I stuck between different implementation techniques and would like
> to learn from other people's experience.
>
It still feels a little kludgy, but this is how I'm doing it
currently...
package MyApp::View::TT;
sub template_vars {
my ( $self, $c ) = @_;
my %vars = $self->SUPER::template_vars( $c );
$vars{ 'site' }->{ 'breadcrumbs' } = $self->breadcrumbs( $c );
return %vars;
}
sub breadcrumbs {
my ( $self, $c ) = @_;
my @breadcrumbs = ();
my @paths = split( '/', $c->req->path );
while ( my $label = pop( @paths ) ) {
next if $label eq 'index';
my $path = join( '/', @paths, $label );
$path = "/$path" unless $path =~ m#^/#;
$label = $self->label_for( $c, $path, $label );
unshift( @breadcrumbs, {
path => $path,
label => $label,
uri => $c->uri_for( $path ),
} );
}
unshift( @breadcrumbs, {
path => '/',
label => 'My Application',
uri => $c->uri_for( '/' ),
} );
return \@breadcrumbs;
}
sub label_for {
my ( $self, $c, $path, $label ) = @_;
if ( my $x = $c->config->{ 'breadcrumbs' }->{ $path } ) {
return $x;
}
$label = join( ' ', map { ucfirst } split( /[_-]/, $label ) );
return $label;
}
1;
[% FOREACH item IN site.breadcrumbs %]
[% IF loop.last %]
[% title or template.title or item.label %]
[% ELSE %]
<a href="[% item.uri %]">[% item.label %]</a> >>
[% END %]
[% END %]
--
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070206/e2a264c0/attachment.htm
More information about the Catalyst
mailing list