The next version of Drupal is shaping up nicely and the current CVS seems pretty stable.
One nice feature in the upcoming release are template "suggestions". This is an array that gets built and converted into a list of filenames to look for alternate templates. This works for pages as well as blocks.
For a given block the phptemplate engine will look for:
This is very nice for customizing layout when launching a site.
However what is missing in my mind is a way for customizing a block's appearance from the block admin interface.
Really the only one of these different options above that is available to the block administrator is the region. Adding regions to a page is a nice way to allow the site administrator to control appearance. But all blocks in a region will have the same appearance.
Two of my pet peeves in this regard are advertising blocks and syndication chicklet icon blocks. When the site has titles and borders around these blocks it degrades what may be an otherwise nice site.
This hits me as a developer/consultant in two specific ways.
As a proof of concept I added a feature that in the block admin interface, the administrator can add a suggestion that will be used as a template name.
For this demonstration I used a hackish method for adding the style suggestion. Entering a string like "{style}" in the block title will cause the template engine to look for a block template file named block-style.tpl.php. The "{style}" will not be displayed on the site.
This is the code:
function phptemplate_block($block) {
$suggestions[] = 'block';
$suggestions[] = 'block-' . $block->region;
$suggestions[] = 'block-' . $block->module;
// If {text} is in block title
if( preg_match("/{([^ \t\r\n}]+)}/", $block->subject, $match)) {
// add template suggestion
$suggestions[] = 'block-' . $match[1];
// remove from block title
$block->subject = preg_replace("/{([^ \t\r\n}]+)}/", "",$block->subject);
}
$suggestions[] = 'block-' . $block->module . '-' . $block->delta;
return _phptemplate_callback('block', array('block' => $block), $suggestions);
}
This simple change puts power into the block administrators hands. The site designer and developer still create any template so only what options they give for each theme is there.
This brings up a couple of discussion points.
Thanks go to the Drupal developers for continuing to extend the flexibility in an elegent manner.
Related Links:
Block admin should have ability to designate appearance "style"
http://drupal.org/node/49775
Commit #77184 by Eaton, look for specific block templates based on region, module, and delta. http://cvs.drupal.org/viewcvs/drupal/drupal/themes/engines/phptemplate/phptemplate.engine?r1=1.39&r2=1.40
The side note is now out of date. The block admin will be able to rename a module's block title in the next Drupal release.
http://cvs.drupal.org/viewcvs/drupal/drupal/modules/block/block.module?r1=1.219&r2=1.220