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 [EMAIL PROTECTED];
}
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 PROTECTED]
http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
_______________________________________________
List: Catalyst@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/