How can I access content within other content types in a template file?

Events happening in the community are now at Drupal community events on www.drupal.org.
aprice42's picture

Hi,

I am working on theming a content type that uses a node reference and I would like to be able to access some content within the other content type that it is referencing.

Here are the details:

The content type is "press" and it references a content type "download". In the press template (node-press.tpl.php) I want to be able to print a direct link to a file that has been added to the download content type being referenced. However, when I look at the available variables with print_r($node) in node-press.tpl.php I only find a link to the entire download node that is referenced, but not to any of the specific content within it.

I know that when you want to access variables for the user you can global $user, is there a similar function so i can essentially global $node->type['download'] so I can grab elements from with that node??

Or is this something that I can set up in a preprocess function?

Any direction would be greatly appreciated

developing in Drupal 6.14

Thanks,
Andy :)

Comments

Using Views to access the

stoob's picture

Using Views to access the other content and display it in a Block or Panel (see "Panels" module) could be one approach.

CiviCRM specialist

Great idea... I hadn't

aprice42's picture

Great idea... I hadn't thought of that approach, I am still learning the ins and outs of views, but I think I will be able to get it to do what I need.

Thanks,
Andy

Alternatively use

mikey_p's picture

Alternatively use views_attach to bring the content from the referenced node into the node template itself.

Or use a preprocess function in a module or theme to do a full node_load on the $nid of the referenced node, and pass that to your template, and use appropriate functions to theme it there. Bonus points for doing all the processing in the preprocess function and returning variables to your template that require nothing more than a simple print $foo statement.

So simple even a senior

stoob's picture

So simple even a senior developer could do it!

Just kiddin around!

CiviCRM specialist

Portland (Oregon)

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: