3

I have a context where I'm placing a block onto a wiki page. Is there anyway for the block to know the node id of the wiki page?

I'd like to write some code in the block's views-view--block--field.tpl.php template file to display something only to the wiki page's owner. With the block being placed on the wiki's page via context, the block needs what node(wiki) page it is displaying and who the node's owner is.

1

Wow - I just got a reply back from Acquia support that answers the issue. menu_get_object() seems to be one of those magically functions I never knew about. Neat.

global $user;
$node = menu_get_object();

if ($node && $user) {

  print '<br/>node uid = ' . $node->uid;
  print '<br/>user uid = ' . $user->uid;

  if ($node->uid == $user->uid) {      
    print t('<br/>You are the author of the current node.');
  }

}
  • 2
    $user will always be initialized to an object, even in the case the current user is the anonymous user. I am not sure what you are achieving by using if ($node && $user) {}. – kiamlaluno Jul 11 '11 at 23:44
0

I think the best way to achieve this would be to use nodereference to reference the content type for the block to the wiki page, and then create an argument in views to limit display to current user.

  • Sorry you lost me a bit... Can you explain how I would use the nodereference and setup the views argument? Thanks Danielle. – gmercer Jul 11 '11 at 1:23
0

I would use hook_node_view() as well but it depends.

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.