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
:-
I can do this in node.tpl.php
through $node->type;
, but unfortunately I need it in html.tpl.php.
Many Thanks.
Add the code to html.tpl.php
<?
$node = node_load(arg(1));
print $node->type;
?>
yeah the answer from @hkinterview could be a possibility.
node_load($node_id) loads the node with the id $node_id, but you have to make sure that arg(1) is the id of the node, for example on view pages this isnt the case.
So you can write
if(arg(1) && is_numeric(arg(1))){
$node = node_load(arg(1));
$type = $node->type;
$title = $node->title;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.