“Breadcrumbs” and “Active trails” in Drupal 8

Tags: Tech Blog Published:

A regular feature we've needed a solution for in any Drupal website build is how to handle showing the breadcrumb and active trail (highlighted menu items). Drupal Core has always catered for this by using the menu structure, but when it comes to placing another page or pages of a certain type into the this active trail, a contributed solution has been required.

BreadcrumbsAn example of when this is needed might be; when you have a news section on your site. You have a content type call “News” and you have a series of views that have paths to display your news articles in an archive by month and by category (taxonomy).

There is the “Menu trail by path” module. This will look at the structure of the path and check if a page exists at each sub path. For example: “news”, “news/category-name” and “news/category-name/title-of-article” might make up three pages that can appear in the breadcrumb. A Drupal 8 release of this module is already available, however it heavily relies on the assumption that nodes have the correct path alias set. The likelihood of this being an issue makes this module less than ideal as a potential solution.

In Drupal 7

For Drupal 7 sites, we opted for the “Menu position” module. This enabled us to set up a highlighted item in the menu, then apply rules to what pages would activate it. For example, if the content type was “news”, or if the first part of the path contained “news”. This pretty much covered all scenarios. Although a port is underway for Drupal 8 at the time of writing, we’ve needed a solution for several months already so, we set about looking for alternative.

Context active trail

For Drupal 8 sites, we are now using the “Context active trail” module. This does everything that menu position does, i.e. choose a menu item and define rules to what pages would activate it and it has the added benefit of being able to be placed into configuration management, unlike menu position, which didn’t integrate into features (configuration in code for Drupal 7). The only real difference is that the administration UI is slightly different and the set up rules do not show in the menu structure in the UI.


So, to sum-up, we’re likely to continue using Context active trail for the foreseeable future - even if Menu Position is finally ported - because we think it’s an all-round better solution.

Let's talk about your project…

Do you have a project in mind that we could help you with?

Get in touch.