Drupal 6 - Better Block Ids Function


/ Published in: PHP
Save to your folder(s)

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

Then call the following section in you block template file.


Copy this code and paste it in your HTML
  1. /*The function*/
  2. <?php
  3. function block_id(&$block) {
  4. $info = module_invoke($block->module, 'block', 'list');
  5. if ($info[$block->delta]['info']) {
  6. $block_id = 'block-' . $block->module . '-' . $info[$block->delta]['info'];
  7. $block_id = str_replace(array(' ', '_'), '-', strtolower($block_id));
  8. return preg_replace('/[^\-a-z0-9]/', '', $block_id);
  9. } else {
  10. return 'block-' . $block->module . '-' . $block->delta;
  11. }
  12. }
  13. ?>
  14.  
  15. /*Call this in your block.tpl.php file*/
  16. <?php print block_id($block); ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.