Return to Snippet

Revision: 5129
at February 13, 2008 09:35 by berkes


Updated Code
/**
 * Return a set of blocks available for the current user.
 * Add a per-region template override option
 */
function ogt_blocks($region) {
  $output = '';
  if ($list = block_list($region)) {
    $function = 'region_'. $region;
    if ($theme_function = theme_get_function($function)) {
      $blocks = array($list);
      //leave the buidling to the dedicated function
      $output = call_user_func_array($theme_function, $blocks);
    }
    else {
      foreach ($list as $key => $block) {
        //Build the string ourselves.
        $output .= theme('block', $block);
      }
    }
  }

  // Add any content assigned to this region through drupal_set_content() calls.
  $output .= drupal_get_content($region);

  return $output;
}

/**
 * Template/theme for the region named "siteinfo" (footer)
 *
 * @return void
 **/
function ogt_region_siteinfo($blocks)  {
  return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
}


//-- in a templatefile region_siteinfo.tpl.php, put something like this:
<?php foreach ($blocks as $block => $block) : ?>
  <?php print theme('block', $block); ?>
<?php endforeach; ?>

Revision: 5128
at February 13, 2008 09:35 by berkes


Updated Code
/**
 * Return a set of blocks available for the current user.
 * Add a per-region template override option
 */
function ogt_blocks($region) {
  $output = '';
  if ($list = block_list($region)) {
    $function = 'region_'. $region;
    if ($theme_function = theme_get_function($function)) {
      $blocks = array($list);
      //leave the buidling to the dedicated function
      $output = call_user_func_array($theme_function, $blocks);
    }
    else {
      foreach ($list as $key => $block) {
        //Build the string ourselves.
        $output .= theme('block', $block);
      }
    }
  }

  // Add any content assigned to this region through drupal_set_content() calls.
  $output .= drupal_get_content($region);

  return $output;
}

/**
 * Template/theme for the region named "siteinfo" (footer)
 *
 * @return void
 **/
function ogt_region_siteinfo($blocks)  {
  return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
}


//-- in a templatefile region_siteinfo.tpl.php, put something like this:
<?php foreach ($blocks as $block => $block) : ?>
  <?php print $block ?>
<?php endforeach; ?>

Revision: 5127
at February 13, 2008 09:18 by berkes


Initial Code
/**
 * Return a set of blocks available for the current user.
 * Add a per-region template override option
 */
function ogt_blocks($region) {
  $output = '';
  if ($list = block_list($region)) {
    $function = 'region_'. $region;
    if ($theme_function = theme_get_function($function)) {
      //leave the buidling to the dedicated function
      $output = call_user_func_array($theme_function, $list);
    }
    else {
      foreach ($list as $key => $block) {
        //Build the string ourselves.
        $output .= theme('block', $block);
      }
    }
  }

  // Add any content assigned to this region through drupal_set_content() calls.
  $output .= drupal_get_content($region);

  return $output;
}

/**
 * Template/theme for the region named "siteinfo" (footer)
 *
 * @return void
 **/
function ogt_region_siteinfo($blocks)  {
  return _phptemplate_callback('region_siteinfo', array('blocks' => $blocks));
}


//-- in a templatefile region_siteinfo.tpl.php, put something like this:
<?php foreach ($blocks as $block => $block) : ?>
  <?php print $block ?>
<?php endforeach; ?>

Initial URL


Initial Description
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.

Initial Title
Allow per-region template overrides.

Initial Tags
template, drupal, theme

Initial Language
PHP