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.
Posted by aprice42 on November 12, 2009 at 9:23pm

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

Posted by stoob on November 13, 2009 at 9:08pm

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

Posted by aprice42 on November 16, 2009 at 8:36pm

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

Posted by mikey_p on November 16, 2009 at 8:57pm

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

Posted by stoob on November 18, 2009 at 7:04pm

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:

AltStyle によって変換されたページ (->オリジナル) /