I am using Contemplate to template my Classified Ads, and I want to display some fields from the posters "Advanced Profile" section. How could I do this? The variable of course is not listed for a selection, but when I go to the Create Template for Advanced Profile and copy those fields into the Classified Ads, it of course does not work.

I assume the Classified Ads template is only pulling data for that node. How do you get it to pull other nodes data as well?

Comments

jrglasgow’s picture

I would use the node_load() function.

$new_node = node_load($nid);// $nid is the ID of the node you want to get data from

Once you have done this you can use $new_node just like $node.

tyler-durden’s picture

Thanks jrglasgow, I think we're on the right path.

However, I may have used the node and module terms loosely, and i'm now a bit confused. The "Advance Profile" module doesn't have a node number from what I can tell, only a number in sequence for each user profile (this may be the node number ???). Also, that number will be different for each poster of the ads, so i'm more confused than ever now.

YesCT’s picture

nice simple solution!

Rosamunda’s picture

I would like to load some cck fields from other content, but that "other content" is from the content profile node, from that node´s author.
So instead of just adding the traditional "Submitted by" I would like to put some more info from each user content profile (not the core profile fields).
So I don´t know what the node number is, how can i relate that to the node´s author?

Thanks!!

jrglasgow’s picture

When setting up the content profile module you create a content type to be the profile. I created the content type 'member profile' on my site. This is how to get the profile node for the user that created the node.

$node_type = 'member_profile'; // what is the node type of your content node
$sql = "SELECT nid FROM {node} WHERE type='%s' AND uid='%s' LIMIT 1"; // query the database to see if there is a node of the proper type authored by the author of the current node
$profile_nid = db_result(db_query($sql, $node_type, $node->uid)); // submit the database query
if ($profile_nid) { // check to see if we have a $profile_nid
  $profile_node = node_load($profile_nid); // get the node data for the profile node
}
Rosamunda’s picture

MANY, MANY, MANY THANKS JAMES!

plan9’s picture

I've read that Drupal's node_load() function fires a great deal of queries and functions. The more module you have, the more node hooks will be involved in this call. Is there any method useable with contemplate to fetch the specific fields directly?

jrglasgow’s picture

@plan9 - no, there are no contemplate specific function to load a node.

plan9’s picture

Thanks for confirming this. I found a way of easing the server load by using computed field module to store static values from other nodes. In this way node_load() function is only used when editing/creating the content - not when viewing contemplate affected teaser / pages.