Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
31 Jan 2011 at 03:44 UTC
Updated:
7 Aug 2011 at 08:33 UTC
Instructions on top of the file mention about $node:
* - $node: The node object, if there is an automatically-loaded node
* associated with the page, and the node ID is the second argument
* in the page's path (e.g. node/12345 and node/12345/revisions, but not
* comment/reply/12345).
However, simple check
if ($node) {
produces an error:
Notice: Undefined variable: node in include() (line 175 of /home/mysite/public_html/sites/default/themes/mysite/templates/page.tpl.php).
Comments
Comment #1
yngens commentedIf anyone is interested I had to replace check to
and it worked as desired. However, imo the above information in page.tpl.php should be modified not to confuse users.
Comment #2
johnalbinThat code comment comes straight from core's page.tpl docs. Moving to Drupal core.
Comment #3
jhodgdonI am not sure what the documentation problem is here. The doc says that $node only exists in some cases, so if you do
and $node doesn't exist, you are guaranteed to get an error on some pages.
So I'm closing this. If someone wants to explain what the doc problem is and reopen (i.e. what about the doc is unclear and could/should be clarified), please feel free.
Comment #4
samhassell commentedThe docs are unclear as to when the node object is available.
I have met the requirements as specified in the docs (ie. on 'node/6') and $node is still not available.
I think this needs some clarification.
Comment #5
jhodgdonIf you are on the page node/6 and node/6 exists, then $node should be available (as the documentation states). It sounds like you have something else wrong and need support.
Although you can create issues in Drupal Core and mark the category as "support request", we don't really handle support requests in the Drupal Core issue queue as a regular practice (that option is mostly there for filing support issues for contributed modules and themes).
There are several support options listed if you click on "Community and Support" at the top of Drupal.org, which will take you to:
http://drupal.org/community
There you can find out about the Drupal IRC channels, and the Forums, which are our two main support mechanisms in the Drupal community.
Good luck with your issue!
Comment #7
Jennifer_M commentedFor the benefit of anyone else coming by to read this thread:
If you are on the page node/6 and node/6 exists, then $node should be available
That's true, but from what I've seen in researching a similar problem, it seems that even if $node is available on that particular page load, PHP may still throw the error based on its analysis of your code. To make PHP happy, you need an
if isset($node), or equivalent, before you call $node itself. (I'm not familiar with yngens' bit of code in #1, but I suspect that it functions similar to anissetquestion.)See
http://drupal.org/node/303492
http://drupal.org/node/1051824#comment-4561536
http://drupal.org/node/1051824#comment-4705798
http://drupal.org/node/37767#comment-4593838 & following bits of thread
Hope this helps someone.
(Not reopening the issue, as I don't think this information belongs in page.tpl.php documentation. The page.tpl.php documentation does what it needs to do, which is inform people that sometimes page.tpl.php doesn't have a $node. What I'm discussing here is really about how PHP deals with scope of variables - it's not specific to one template.)