Skip to content

Instantly share code, notes, and snippets.

@machuga
Created July 2, 2012 00:49
Show Gist options
  • Save machuga/3030270 to your computer and use it in GitHub Desktop.
Save machuga/3030270 to your computer and use it in GitHub Desktop.
Simplistic Laravel Breadcrumb macro
<?php
HTML::macro('breadcrumbs', function() {
$links = '';
$current = URI::current();
if ($current != '/')
{
return array_reduce(explode('/', URI::current()), function($t,$c) use (&$current, &$links) {
$links = $links ? $links.'/'.$c : $c;
$active = 'active';
$divider = '';
$content = Str::title(str_replace(['_', '-'], ' ', $c));
if ($current != $links)
{
$active = '';
$divider = '<span class="divider">/</span>';
$content = HTML::link($links, $content);
}
$html = '<li class="'.$active.'">'.$content.'</li>'.$divider;
return $t .= $html;
});
}
else
{
return '<li class="active">Home</li>';
}
});
@adamjleonard
Copy link

Removed bad implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment