A block changes its ID when moved between regions?
Under Drupal 6 I have a custom block, which I have named and placed into a custom, right-hand sidebar region. This block's ID (which I have discovered from block.tpl.php
, from the $block_id
helper variable) is 7.
I am overriding the output of this block as it displays a View and I need to change the markup; I have a preprocess function in template.php
called myTheme_preprocess_block()
which searches for the block's unique ID thus:
myTheme_preprocess_block(&$vars) {
$this_block_id = $vars['id']; /* region-independent ID (for reliability) */
$vars['template_files'] = array();
switch ($this_block_id) {
case 7:
$vars['template_files'][] = 'block-my-override-template';
break;
default:
/* take no action */
}
}
Now, I've moved this block from the right-hand sidebar region (which is a custom region and not the default one which comes with Garland) to a footer region, which also has a custom name. And suddenly, my overriding template file, block-my-override-template.tpl.php
, is no longer referenced.
I do a little digging and output the unique block ID from within block.tpl.php
, and magically this block has changed its ID from 7 to 13! With a straight face, no less! Returning this block to the right-hand sidebar region also returns the block to ID 7 (and all my code starts working again).
My question is this: How can we uniquely identify a bloc开发者_运维问答k if its "unique" ID changes when it moves from one region to another?
If you are using a View, why don't you instead override the block display of the View instead of mucking around with the actual block?
You could alternatively simply declare your custom block in a module? That should make it easier for you to manage theming aspects of the block.
精彩评论