[drupal-support] $node not always available

Adrian Rossouw adrian at bryght.com
Wed May 4 15:13:11 UTC 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 04 May 2005, at 11:07 AM, Gerhard Killesreiter wrote:

>
>
> On Tue, 3 May 2005, Maykel Moya wrote:
>
>> I recently asked for a way to know the current viewed node, someone
>> point me to global $node. The problem is that the variable is
>> randomly available, sometimes it have the correct content, sometimes
>> is empty.
>>
>> This is probably a bug of Drupal core. I'm using CVS HEAD.
>
> No, this is by design. $node is not a global variable.
>
>> I'm thinking using global $_menu['local tasks'] and do some tricky
>> parsing to find out the current viewed node.
>
> You can parse the url instead (arg(0) == 'node' && is_numeric(arg(1))).
Additionally .. you can retrieve the node using node_load (it caches 
internally.. )

so
if ((arg(0) == 'node') && is_numeric(arg(1))) {
   $node = node_load(array('nid' => arg(1));
}
will populate the node variable.

- --
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFCeOZ1gegMqdGlkasRAk56AKCTwdKpP04LuDIA1GivdWI6EitQdACfd8lt
M7HMHJeUEPQBHQpqrv02sSc=
=T5jD
-----END PGP SIGNATURE-----




More information about the drupal-support mailing list