Return to Snippet

Revision: 39614
at January 19, 2011 03:26 by Onfire60


Initial Code
/*The function*/
<?php
function block_id(&$block) {
  $info = module_invoke($block->module, 'block', 'list');
  if ($info[$block->delta]['info']) {
    $block_id = 'block-' . $block->module . '-' . $info[$block->delta]['info'];
    $block_id = str_replace(array(' ', '_'), '-', strtolower($block_id));
    return preg_replace('/[^\-a-z0-9]/', '', $block_id);
  } else {
    return 'block-' . $block->module . '-' . $block->delta;
  }
}
?>

/*Call this in your block.tpl.php file*/
<?php print block_id($block); ?>

Initial URL

                                

Initial Description
Copy the first code snippet to your theme's template.php.

Then call the following section in you block template file.

Initial Title
Drupal 6 - Better Block Ids Function

Initial Tags
drupal

Initial Language
PHP