Skip to content

Instantly share code, notes, and snippets.

@Karting06
Forked from Aeotrin/breadcrumb-cache.theme
Created August 15, 2021 12:24
Show Gist options
  • Save Karting06/7b083fc2950669544779d5e4abe957a7 to your computer and use it in GitHub Desktop.
Save Karting06/7b083fc2950669544779d5e4abe957a7 to your computer and use it in GitHub Desktop.
Drupal 8 - Breadcrumb Preprocess and Cache
function theme_preprocess_breadcrumb(&$variables) {
if (($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']) {
$variables['breadcrumb'][] = [
'text' => $node->getTitle()
];
$variables['#cache']['contexts'][] = 'url.path';
}
}
function theme_preprocess_breadcrumb(&$variables) {
if (($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']) {
$variables['breadcrumb'][] = [ 'text' => $node->getTitle() ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment