Trouble accessing populated $node using node_load($nid) from theme override of taxonomy_router/tr-node-item.tpl.php

webel - June 22, 2009 - 06:45

Context: I am using Taxonomy TreeMenu with Taxonomy Router because Taxonomu Menu is failing with multiple parents and "display descendants".

#498226: Primary Links menu completely mangled, and stayed mangled after switching off module !

#498182: Support for a term with multiple parents

This gives descendants also, however the display from taxonomy_router/tr-node-item.tpl.php (and taxonomy_router/page-branch-list.tpl.php) is not what I want, I'd like to make it look like my regular highly customised teasers.

However the teaser code from my custom node-MYTYPE.tpl.php requires a populated $node

The $nid is provided by taxonomy_router/tr-node-item.tpl.php, so in my override I try to get at $node using:

$node = node_load($nid)

OR

$node = node_load(array('nid' => $nid));

Then I simply include my own .tpl.php (as used for front page teasers and custom type body).

It works only partially, as the $node does not seem to be fully populated (contrary to the docs on node_load). The current result can be seen here:

http://www.ethicalemarket.com/category/1/1

Compare with the front page teasers:

http://www.ethicalemarket.com

The only thing that seems to be in $node is the title, otherwise it's empty.

I also tried to use the cache reset, it did not seem to have any effect:

$node = node_load(array('nid' => $nid),$revision,$reset);

Q: How can I ensure the $node obtained from the $nid is properly populated ?

Problem solved, answer is node_build_content()

webel - June 22, 2009 - 07:42

Webel, "Elements of the Web", Scientific IT Consultancy,
For UML, UML Parsing Analysis, SysML, Java, XML, and Drupal CMS
http://www.webel.com.au
http://www.ethicalemarket.com
http://play.webel.com.au
"See a need, fill a need", Bigweld (from "Robot

No, not entirely solved: some CCK fields are not loaded

webel - June 22, 2009 - 08:30

Please compare teasers in http://www.ethicalemarket.com/ (which have image URLs and prices via CCK displayed ok) with http://www.ethicalemarket.com/category/1/23/20,
which has the images ok, but for some reason the price (Murphy's law working here) is missing.

I used node_load() then node_build_content().

Q1: Is there anything else I must do to force population of CCK data into $node ?

Q2: If so, why are some CCK fields ok, while others have missing ?

Very glad for any suggestions.

Webel, "Elements of the Web", Scientific IT Consultancy,
For UML, UML Parsing Analysis, SysML, Java, XML, and Drupal CMS
http://www.webel.com.au
http://www.ethicalemarket.com
http://play.webel.com.au
"See a need, fill a need", Bigweld (from "Robot

For some reason the ['view'] element of Money field array empty

webel - June 22, 2009 - 11:03

I used the devel module's dpr($array) diagnostic output to examine my $node and discovered that for some reason when it is obtained using node_load($nid) then node_build_content($nid) the ['view'] element of my Money field is empty (I was relying on that in my included .tpl.php snippet), whereas the ['amount'] and ['currency'] data are correct.

So I have a workaround and can progress with my site development, however I still don't understand why, and remain glad for any feedback on this.

Webel, "Elements of the Web", Scientific IT Consultancy,
For UML, UML Parsing Analysis, SysML, Java, XML, and Drupal CMS
http://www.webel.com.au
http://www.ethicalemarket.com
http://play.webel.com.au
"See a need, fill a need", Bigweld (from "Robot

 
 

Drupal is a registered trademark of Dries Buytaert.