Set block region
dropcube - February 3, 2009 - 16:28
| Project: | Component |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
When you get block content with component_get_block($module, $delta, ...), the theme system doesn't know about the possible region where the block is being rendered. For this reason, region based template suggestions for the block doesn't work. For example, imagine you want block themed as it would be in the left sidebar, and the same block themed as it would be in the footer.
Would be good to specify a region such that theme hook knows about it and use the template suggested based on the region. Here is the code. I can provide a patch later.
<?php
function component_get_block($module, $delta, $title_text = NULL, $region = NULL) {
$block = (object) module_invoke($module, 'block', 'view', $delta);
$block->module = $module;
$block->delta = $delta;
if (isset($region)) {
$block->region = $region;
}
if (isset($title_text)) {
$block->subject = check_plain($title_text);
}
$output = theme('block', $block);
return $output;
}
?>
#1
#2
Except that the block is not IN that region, so I don't see why you'd want to pretend it is. Your template would effectively be wrong.
#3
I explain with a use case. Suppose you want to pull the content of the user login block to put it anywhere, but you don't want to use the default block template of your theme (block.tpl.php), instead you would like to use the templates suggested based on the region (for example block-sidebar_left.tpl.php), and have the block themed with that template. Currently this is not possible because you can not specify a region.
Other templates may use the region variable for something, to generate IDs, etc..., and you would like to render the blocks with a 'valid' region value.
Anyway, such $region argument would be optional, do not affect the current behavior.
#4
Attached a patch.