2

I'm using module_invoke() to include a block and I need in this block to read a value contained in my parent content type page. So how can I get the $node variable in my block from the view?

Code I'm using:

<?php
    $block = module_invoke('my_blocks', 'block', 'view', 7);
    print $block['content'];
?>

Now I need to access $node in "my_blocks" and the variable is empty. What can I do to get it?

Thanks a lot for any help!

Regards

apaderno
  • 28,547
  • 16
  • 75
  • 90
Benoit Wickramarachi
  • 6,096
  • 5
  • 36
  • 46

2 Answers2

1

I think the context module or chaos tools can help with that, but here's how I did the same thing recently:

function myModule_get_current_node() {
    $path_arr = explode('/', $_GET['q']);
    if ($path_arr[0] == 'node') $result = node_load($path_arr[1]);
    else $result = null;
    return $result;
}
sprugman
  • 19,351
  • 35
  • 110
  • 163
1

little fix to drupal way:


    function InMODULE_or_InTHEME_get_current_node() {
      if ((arg(0) == 'node') && (is_numeric(arg(1))) && (!arg(2))) return node_load(arg(1));
      return null;
    }

Comments: node_load cache nodes, so don't worry about perfomance.
"!arg(2)" is checking for just you don't in node edit mode (or something like).

Nikit
  • 5,128
  • 19
  • 31