Adam Jensen

Recent Blog posts

blocks

Using Block Visibility Groups to Create Conditional Layouts in Drupal 8

Posted on Monday, March 28, 2016 - 10:05

Recently I had a customer ask me how to tell Drupal 8 to display certain blocks conditionally, based on whether or not the node page being viewed referenced certain taxonomy terms. In Drupal 7 I would have recommended the Context module for this, but as it’s not yet ready for Drupal 8 I had to go looking for other options.

My search led me fairly quickly to the brand-new Block Visibility Groups module, which aims to provide the same sort of conditional block visibility functionality that Context provides, but in a manner that integrates more closely with the core Block UI. It works well, but doesn’t natively provide support for basing visibility off of node field data (such as taxonomy term references). However, since Block Visibility Groups uses the core D8 Condition plugin type to define its conditions, all that’s needed is to implement a custom plugin to get the desired behavior. Here’s how it works, from start to finish:

Subscribe to Recent Blog posts