3

I need to find out what region the node block is appearing in within the node template. I am using node block module to display nodes as blocks but need to know what region the node blocks are appearing in within the node.tpl. In Drupal 6 there was a template preprocess function where you could set a global var to accomplish this but that function is not available in D7. Thanks for any help.

It won't let me answer my question yet so I will put it here.

If anyone else runs into this and wants to know what region the node is being displayed in within the node template using the node block module or something like it. You can use the template_preprocess_node($vars) function and add the region to the content so that it will be in the content array in the node template like this.

$vars['content']['region']=$vars['elements']['#block']->region;

  • 1
    Hi Chris, can you post your solution as as a separate answer? This way, it's clear what the solution is and it'd allow people to vote it up as the proper solution. – user7 Jan 20 '12 at 22:49
2

If anyone else runs into this and wants to know what region the node is being displayed in within the node template using the node block module or something like it. You can use the template_preprocess_node($vars) function and add the region to the content so that it will be in the content array in the node template like this.

$vars['content']['region'] = $vars['elements']['#block']->region;
1

There is a variable for that: $block->region. This and other variables that are available inside the block template can be found inside the commented-out area (at the top of the template).

  • yeah sorry I just realized I asked that wrong I actually need to know the region in my node.tpl and not the block.tpl because I am using node block module. is there a way to pass it from the block tpl to the node tpl? – Chris Jan 20 '12 at 17:32
  • Congrats for finding the answer by yourself. +1 for posting it. – ovi Jan 20 '12 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.