Drupal 6 - Stop views from giving block ids a hash name - Block Preprocess


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

This code goes directly into your template.php file after you remove the open and close PHP tags at the beginning and end.

Then place the call below in your block.tpl.php. Don't forget to flush cache.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /**
  4.  * Hook Preproccess Block
  5.  */
  6. function phptemplate_preprocess_block(&$vars) {
  7. $block = $vars['block'];
  8. $chars_delta = strlen($block->delta);
  9. // don't do anything if this block is not from views module or if delta < 32 chararacters
  10. // because md5 is always 32
  11. if ($block->module == 'views' && $chars_delta >= '32') {
  12. //get from variable table the hashes and their corresponding views name, in an associative array
  13. $hashes = variable_get('views_block_hashes', '');
  14. // add a nice new template suggestion if this delta is a hash
  15. if(isset($hashes[$block->delta])) {
  16. $block->custom_classes['block_id'] = $block->module .'-'. $hashes[$block->delta];
  17. $vars['template_files'][] = $block->custom_classes['block_id'];
  18. }
  19. }
  20. else {
  21. // just set the normal block id for css
  22. $block->custom_classes['block_id'] = $block->module .'-'. $block->delta;
  23. }
  24. }
  25.  
  26. ?>
  27.  
  28.  
  29.  
  30. /*How to call this in block.tpl.php*/
  31. <div id="block-<?php print $block->custom_classes['block_id']; ?>" class="clear-block block block-<?php print $block->module ?>">

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.