I want to breadcrumb in drupal8
that display as url as home / list page / node page.
I just have in breadcrumb home > node page.
I use bootstrap breadcrumb.
2 Answers
Drupal 8 uses the page alias to build up the breadcrumb trail. Your "node page" would need to contain the "list page" alias to make it work e.g. List page = /mylist Node page = /mylist/mynode
If you want to use the menu structure then you could try this https://www.drupal.org/project/menu_breadcrumb
You can do it with theme_breadcrumb function. You just need to add you condition and return.In below example I am taking service node type page and list page which is created by views page and path is service.So my breadcrumb should be like this
Home>services>Service title
function theme_breadcrumb(&$variables){
$path = \Drupal::service('path.current')->getPath();
$path_args = explode('/', $path);
$home_link = \Drupal\Core\Link::createFromRoute('Home', '<front>');
$output = '';
if(($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']){
$typeName = $node->bundle();
if ($typeName == 'service') {
$url_object = \Drupal::service('path.validator')->getUrlIfValid('service');
$route_name = $url_object->getRouteName();
$service_link = \Drupal\Core\Link::createFromRoute('Services', $route_name);
$breadcrumb = array();
$breadcrumb[] = $home_link->toString();
$breadcrumb[] = $node->getTitle();
$output .= '<div class="breadcrumb">' . implode('<i>></i> ', $breadcrumb) . '</div>';
return $output;
}
}
}