Add meaningfully template suggestions for blocks

Public

Really useful for theming, particularly the block description one.
The available templates for any block will be:

block--REGION.tpl.php
block--MODULE.tpl.php
block--DELTA.tpl.php
block--DESCRIPTION.tpl.php

Add it to your theme's template.php file.

Get raw version
php
  1. function MYTHEME_preprocess_block(&$variables) {
  2. $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->region;
  3. $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->module;
  4. $variables['theme_hook_suggestions'][] = 'block__' . $variables['block']->delta;
  5.  
  6. // Add block description as template suggestion
  7. $block = block_custom_block_get($variables['block']->delta);
  8.  
  9. // Transform block description to a valid machine name
  10. if (!empty($block['info'])) {
  11. setlocale(LC_ALL, 'en_US'); // required for iconv()
  12. $variables['theme_hook_suggestions'][] = 'block__' .
  13. str_replace(' ', '_', strtolower(iconv('UTF-8', 'ASCII//TRANSLIT', $block['info'])));
  14. }
  15. }