I am trying to access the current $node variables in the html.tpl.php within Drupal 7. The problem is that I am running a Analytics software in the backend for which I've to record each page's analytics from html.tpl.php.

If there's a normal page, I have to record generic attributes but if it's a node, I need the following things in the html.tpl.php:-

  • Title of the Content (Node)
  • Content Type of the Content

I can do this in node.tpl.php through $node->type;, but unfortunately I need it in html.tpl.php.

Many Thanks.

1 Answer 1


You can get the current menu object with menu_get_object(). From there you can determine if that object is a node or not. Since it defaults to "node" it will be empty if you're not on a node page and will have all the normal node object stuff available if you are.

$node = menu_get_object()
  • That's great! Let me try that. I'll post any problems here. Thanks.
    – user219492
    Dec 18, 2013 at 20:13

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.