Display Blocks Based on Node Taxonomy in Drupal without Coding

The Problem

I needed to display a block based on a few conditions:

  • Display on the node page for a particular content type.
  • Only show up if that node had a particular taxonomy term assigned.

Drupal let's you control the visibility settings for blocks, but the options are limited to Pages, Content types, Roles, and Users. Content types would allow me to let the block appear for my content type, but not based on it's taxonomy terms.

After looking around for a contributed module or a code snippet that could solve my problem, I had an epiphany. I could use the URL Alias, Pathauto, and the block visibility settings by page to accomplish the same thing. Pathauto allows you set patterns when generating aliases based on content type and even taxonomy fields attached to nodes.

The Solution

With Pathauto enabled, set the URL Alias pattern for your content type to "[field: term_<my taxonomy reference field name>]/[node:title]". Then set the block visibility based on Pages to "<my term name>/*"


It's a simple solution, but this might not work for every scenario. It worked for me because I was checking for a taxonomy term that could only have one value. The form on my node was a single select list. Not that it wouldn't be possible to use URL Alias patterns for more complex scenarios, but it did make it significantly easier.