4

I see that when I am creating a block through the drupal admin I can use PHP, in addition to plain text & html. Is there a variable in scope that I can use to access the node id?

<?php echo my_custom_function( $node_id, $my_desired_class); ?>

1 Answer 1

11

You can use the menu_get_object() function which will get you the node object for the page, assuming of course your block is being displayed on a node page:

$node = menu_get_object();

if (isset($node->nid)) {
  $nid = $node->nid;
  echo my_custom_function($nid, $my_desired_class);
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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