Skip to content

Instantly share code, notes, and snippets.

@lukzgois
Created December 16, 2015 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukzgois/dc77c54a06ccb0bb8ebd to your computer and use it in GitHub Desktop.
Save lukzgois/dc77c54a06ccb0bb8ebd to your computer and use it in GitHub Desktop.
Lavarel blade breadcrumbs
Blade::directive('breadcrumbs', function ($expression = null) {
return "
<ol class=\"breadcrumb\">
<li><a href=\"/\">Home</a></li>
<?php if(isset(\$expression)): ?>
<?php foreach(with($expression) as \$text => \$link): ?>
<?php if(!is_int(\$text)): ?>
<li>
<a href=\"<?php echo \$link ?>\">
<?php echo \$text ?>
</a>
</li>
<?php else: ?>
<li class=\"active\"><?php echo \$link ?></li>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
</ol>
";
});
// vai gerar apenas um link "home"
@breadcrumbs
// irá gerar um link home, e um link users para a página /users
@breadcrumbs([
'users' => '/users'
])
// irá gerar um link home, e um link users para a página /users e um texto sem link "editar"
@breadcrumbs([
'users' => '/users',
editar
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment