-
Notifications
You must be signed in to change notification settings - Fork 415
Automatically determine breadcrumbs from current route #16
Comments
I use this code, which works but probably isn't the best solution. function has_breadcrumb($name = NULL) {
if ($name === NULL) {
$name = Route::currentRouteName();
}
$excluded = ['home']; //TODO Move to config.
if (in_array($name, $excluded)) {
return FALSE;
}
return in_array($name, Breadcrumbs::getRegistered());
}
/**
* Render the breadcrumb for a certain route. (If it has one.)
* @param string $name The route to display breadcrumbs for.
* @param array $routeParameters Any route parameters to use. For example, the selected category.
* @return string|NULL Returns the breadcrumb HTML if successful, otherwise NULL.
*/
function render_breadcrumb($name = NULL, $routeParameters = array()) {
if ($name === NULL) {
$name = Route::currentRouteName();
}
if (has_breadcrumb($name)) {
return Breadcrumbs::render($name, $routeParameters);
}
} As you can see, it requires a small modification to the Breadcrumbs library; a way to get the currently added breadcrumbs. ($this->callbacks) This only works for named routes though, and you have to send Edit: This doesn't actually work since the 2.x update. |
Since 2.0 you probably need An alternative to |
I think this is resolved here #24 |
Released in 2.2.0. |
I don't yet know if this is possible but I'd like to try to determine the current breadcrumbs from the current route name & parameters, so that it's not necessary to specify these again in the view.
This may not be possible since not all routes are named...
The text was updated successfully, but these errors were encountered: