Allow per-region template overrides.


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

A per-region override.
ogt_blocks is ran for a region, if a region contains blocks, we search for a theme function named theme_region_regionname(). If exists, we run that, else we just return the concatenated blocks for that region.


Copy this code and paste it in your HTML
  1. /**
  2. * Return a set of blocks available for the current user.
  3. * Add a per-region template override option
  4. */
  5. function ogt_blocks($region) {
  6. $output = '';
  7. if ($list = block_list($region)) {
  8. $function = 'region_'. $region;
  9. if ($theme_function = theme_get_function($function)) {
  10. $blocks = array($list);
  11. //leave the buidling to the dedicated function
  12. $output = call_user_func_array($theme_function, $blocks);
  13. }
  14. else {
  15. foreach ($list as $key => $block) {
  16. //Build the string ourselves.
  17. $output .= theme('block', $block);
  18. }
  19. }
  20. }
  21.  
  22. // Add any content assigned to this region through drupal_set_content() calls.
  23. $output .= drupal_get_content($region);
  24.  
  25. return $output;
  26. }
  27.  
  28. /**
  29. * Template/theme for the region named "siteinfo" (footer)
  30. *
  31. * @return void
  32. **/
  33. function ogt_region_siteinfo($blocks) {
  34. return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
  35. }
  36.  
  37.  
  38. //-- in a templatefile region_siteinfo.tpl.php, put something like this:
  39. <?php foreach ($blocks as $block => $block) : ?>
  40. <?php print theme('block', $block); ?>
  41. <?php endforeach; ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.