$node Variable not Accessible in Page Template for Nodes That Match Rule

eweber - October 27, 2009 - 17:37
Project:Node breadcrumb
Version:6.x-1.0-beta6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I created a simple rule that assigns a certain menu item for a content type. As soon as that is done I don't have a $node object anymore when I access it in my page.tpl.php. When I delete the rule or deactivate node_breadcrumbs everything works as intended. Am I missing something or is this a bug?

#1

edhel - October 27, 2009 - 17:58

Drupal does not set $node variable in page.tpl.php. Do you set it in template.php? Show your code where you init it.

#2

eweber - October 27, 2009 - 18:21

It doesn't? Ok, then I have a fundamental understanding problem. I never initialize $node, I just use it. But I also checked and I cannot access $node directly in the page.tpl.php.

I should clarify. I have a custom theme, in the page.tpl.php I call a function that renders some links for the current node based on the users permission

<?php print dart_render_operations($node) ?>

In my template.php file the actual function is

function dart_render_operations ($node) {
    $menu_item = menu_get_item();
    $active_path = $menu_item["href"];

    $output = "";
    if (node_access("create", $node->type)) {
...
    }
    if (node_access("update", $node)) {
...
    }
    if (node_access("delete", $node)) {
...
    }

    return $output;
}

This way the $node variable is set correctly and I can access it. However, I never initialized it knowingly. I've seen this usage in some default theme and just assumed that it is there (and it worked curiously).
But as you said I cannot access $node from the page.tpl.php. So I'm assuming it is injected from Drupal's template mechanism somewhere when the template is parsed?

Anyway, using this construction everything works when I don't have a rule defined for node_breadcrumb. As soon as I define a rule for a content type the above routines don't work anymore.

#3

edhel - October 28, 2009 - 01:47

http://drupal.org/node/572718 - similar issue

Add this code to dart_render_operations as first line:

if (!$node && arg(0) == 'node' && is_numeric($nid = arg(1))) $node = node_load($nid);

PS: Here vars for page.tpl.php http://api.drupal.org/api/drupal/modules--system--page.tpl.php and there are no $node var.

 
 

Drupal is a registered trademark of Dries Buytaert.