Custom template for block

I’m using Node Blocks to create blocks for a bunch of different content types and I thought I needed to theme the block template on a per content type basis. Turns out I don’t, but it took me a long time to figure out so I wanted to record it for posterity. You can actually use this technique to make a new block template with any logic you’d like. Any data you can grab in template_preprocess_block is up for grabs. Then, add your template name to the theme_hook_suggestions array:

function template_preprocess_block(&$variables, $hook) {
$variables['theme_hook_suggestions'][] = 'block__custom';
}

Your custom template should have the name block–custom.tpl.php. This is in Drupal 7, BTW.

Discussion Area - Leave a Comment