Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By theropodx on
After upgrading to 5.10, I noticed a problem in my template. Calling a node via node_load ceased working. This line now returns empty:
$thisnode = node_load(array('nid'=>$node->nid));
I finally tracked down this workaround which does in fact return the node data:
if ( arg(0) == 'node' && is_numeric(arg(1)) ) { $nodeid = arg(1); }
$thisnode = node_load($nodeid);
I'm not 100% certain the break came with the 5.10 upgrade. Anybody else know for sure what might have broken "$node->nid"?
Comments
Where (what context) are you
Where (what context) are you using $node->nid?
Well the immediate context
Well the immediate context is the first code snippet i posted above. This code was in the body of my chameleon-derived template file. The purpose of the code is to discover what content type the node is and then hide or show the node title based on the content type. Works fine now, and worked fine before. Just wondering what broke the original code.
just found out it was
just found out it was actually 5.8 that broke this. still not sure what changed.
subscribing
subscribing
In your first code segment,
In your first code segment, I'm not sure why you would need to use node_load if you already have the $node variable. I would think you would want to do something like:
or a little easier to understand: