7.x common.inc drupal_get_region_content($region = NULL, $delimiter = ' ')

Gets assigned content for a given region.

Parameters

$region: A specified region to fetch content for. If NULL, all regions will be returned.

$delimiter: Content to be inserted between imploded array elements.

2 calls to drupal_get_region_content()
DrupalSetContentTestCase::testRegions in modules/simpletest/tests/common.test
Test setting and retrieving content for theme regions.
template_preprocess_maintenance_page in includes/theme.inc
Process variables for maintenance-page.tpl.php.

File

includes/common.inc, line 193
Common functions that many Drupal modules will need to reference.

Code

function drupal_get_region_content($region = NULL, $delimiter = ' ') {
  $content = drupal_add_region_content();
  if (isset($region)) {
    if (isset($content[$region]) && is_array($content[$region])) {
      return implode($delimiter, $content[$region]);
    }
  }
  else {
    foreach (array_keys($content) as $region) {
      if (is_array($content[$region])) {
        $content[$region] = implode($delimiter, $content[$region]);
      }
    }
    return $content;
  }
}

Comments

Sivaji’s picture

This api does not exist for d8.

N1ghteyes’s picture

If you need to populate region tpl files with page array data use this:

function THEME_preprocess_region(&$variables){
	switch ($variables['elements']['#region']) {
		case 'header_area':
			foreach (system_region_list($GLOBALS ['theme']) as $region_key => $region_name) {
				if (!isset($variables ['page'][$region_key])) {
					$variables ['page'][$region_key] = array();
				}
				if ($region_content = block_get_blocks_by_region($region_key)) {
					$variables ['page'][$region_key] = $region_content;
				}
			}

			// Set up layout variable.
			$variables ['base_path'] = base_path();
			$variables ['front_page'] = url();
			$variables ['logo'] = theme_get_setting('logo');
			$variables ['main_menu'] = theme_get_setting('toggle_main_menu') ? menu_main_menu() : array();
			$variables ['secondary_menu'] = theme_get_setting('toggle_secondary_menu') ? menu_secondary_menu() : array();
			$variables ['site_name'] = (theme_get_setting('toggle_name') ? filter_xss_admin(variable_get('site_name', 'Drupal')) : '');
			$variables ['site_slogan'] = (theme_get_setting('toggle_slogan') ? filter_xss_admin(variable_get('site_slogan', '')) : '');

			if ($node = menu_get_object()) {
				$variables ['node'] = $node;
			}

		break;
	}
}
N1ghteyes’s picture

I should mention this is locked to a specific region. remove the switch/case around the code to apply to all regions.