Thursday, July 7, 2011

How to assign content to the region without blocks?

If you want to assign content to regions but not have it output via blocks, do so with the drupal_set_content() function. This allows you to bypass the regular block system. Try something like this:

Set content to regions
In your module code, set content to the regions. You can use region names that aren't listed in your themename_regions() array. That way, the regions won't be available for blocks, and so won't end up with block content in them. Say your regions are called 'region1' and 'region2'. In your module code, do this:

= 'whatever';
drupal_set_content('region1', $output);
?>

In a template.php file, set a variable and assign the region content to it.

function _phptemplate_variables($hook, $variables) {
// Load region content assigned via drupal_set_content().
if ($hook == 'page') {
foreach (array(
'region1', 'region2') as $region) {
$variables[$region] = drupal_get_content($region);
}
}
return
$variables;
}
?>

Output your content
In your page.tpl.php file, output the regions where you want them:

print $region1;
?>

No comments:

Post a Comment