0

I have a custom theme that has base theme: classy setting in the mytheme.info.yml file. When we enable twig debugging locally, we find that the <!-- BEGIN OUTPUT from 'themes/custom/mytheme/templates/navigation/breadcrumb.html.twig' --> is displayed, but there are no theme suggestions available.

This is what displayed on the page.

enter image description here

How can we create theme suggestions for breadcrumbs?

We tried the following in the mytheme.theme file, but it did not print out the ksm() statements.

function mytheme_theme_suggestions_breadcrumb_alter(array &$suggestions, array $variables) {
  ksm($suggestions); // this returns empty
  ksm($variables); // this only returns theme_hook_suggestion and links array
}

The code is based off of what we can do for block suggestions alters.

function mytheme_theme_suggestions_block_alter(array &$suggestions, array $variables) {
  if (isset($variables['elements']['content']['#block_content'])) {
    $suggestions[] = 'block__' . $variables['elements']['content']['#block_content']->bundle();
  }
}
  • By default $suggestions because there is no other suggestion, if you want another suggestions just add them to $suggestions – berramou Jan 26 at 22:36
  • @berramou the problem is that normally i would be able to get the machine name of the entity (i.e. mybreadcreamb), but I can't get that from $variables – usernameabc Jan 26 at 23:30
  • 1
    Breadcrumbs aren’t entities - what entity are you hoping to get a reference to in the theme suggestions hook? – Clive Jan 27 at 8:45
  • as @Clive said breadcrumbs aren’t entities, can you update your question, which suggestion you want to add to breadcrumb ? – berramou Jan 27 at 9:13
  • @Clive I was hoping to do something similar to what can be done with blocks – usernameabc Jan 27 at 19:36
0

As mentioned by @Clive, breadcrumbs are not entities so I was not be able to get it done by adding a mytheme_theme_suggestions_breadcrumb_alter. Instead to solve the problem I had to do the following. On top of this, I ended up downloading and enabling Easy Breadcrumb to further modify the Breadcrumb

  1. Copy the breadcrumb.html.twig file from the Classy theme into my mytheme directory
  2. Clear cache
  3. make any edits into the sites/themes/custom/mytheme/templates/navigation/breadcrumb.html.twig file
  4. save and clear cache (if necessary)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.