I'm using CCK and Views.

I want to be able to create a node A that references node B and automatically calls in the teaser for B.

Using CCK I can create a field in my content type for "nodereference" that will link to the title of B, but I really want to see the whole teaser.

Is there a way to do that?

Comments

kkronyak’s picture

If you are using the Content Template module, you can do this easily. You can try the following:

<?php
  $importednode = node_load($field_nodefield[0]['nid']);
?>

Assuming "nodefield" is the name of your nodereference field. $importednode will then contain the complete node, including teaser.

If you are not using Content Template, you could probalby use a similar mechanism with the "computed field" field type in CCK.

ktnk’s picture

I am also wondering how to display the referenced nodes as teasers rather than just titles.

Does the above advice still work for Drupal 5?

Can someone help to complete this example to show how to handle a node reference field with multiple values, and how to display those values?

Thanks,
Ktnk

megg’s picture

the above code (from kkronyak) generated errors in my drupal 5 installation.

i'd really like to know how to do this, too. perhaps it is just too easy to do and we're missing something really obvious?

edex13’s picture

i try ur code but not working. maybe there is other steps that u need to explain

dtabach’s picture

Here (drupal 5.2), the code did not generate errors, but nothing happens.

If you add

<?php print $importednode->teaser ?>

after the code provided by kkronyak, you will have your teaser.

Durval Tabach

Durval Tabach

dtabach’s picture

I still did not find out how to pull specific cck fields from the referenced node, instead of its teaser or body. Any clues?

Durval Tabach

ellanylea’s picture

There is ongoing discussion and development here: http://drupal.org/node/123482

---------------------------------------------------
AdAstra.ca - Optimize the Web. Optimize the World.

dtabach’s picture

I eventually found a way to display CCK fields from referenced nodes.
For example, let's say you have a 'Meeting' content type, and a 'Place' content type.
'Meeting' has the field 'where', which is a nodereference to a 'Place' node.
'Place' has the field 'address', which you want to display in the 'Meeting' node.

Sou you put this into your node-meeting.tpl.php:

<?php /* reads info from Place */
  $importednode = node_load($field_where[0]['nid']);
?>
<?php foreach ((array)$importednode->field_address as $item) { ?>
<div class="field-address"><?php print check_markup($item['value']) ?></div>
<?php } ?>

Durval Tabach

Durval Tabach

dtabach’s picture

If you want to email your 'Meeting' node using the Send module, it will not add the 'where' information.

Durval Tabach

Durval Tabach

dtabach’s picture

If you want to email your 'Meeting' node using the Send module, it will not add the 'where' information.

It won't, if you use node-meeting.tpl.php. But it will, if you put the code above in the "affect body output' provided by Contemplate module.

Durval Tabach

summit’s picture

Subscribing, will this functionality be integrated in cck node reference (drupal 5)? Greetings, Martijn

socialnicheguru’s picture

thanks again.

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.

amaltemara’s picture

This method of 'node_load' must be expensive!

It must execute another sql query every time it's called.

In CCK, is there any sort of "eager loading" functionality in drupal such as in Rails?

In Rails, it works like this: You specify the 'content types' that you want to pull in, and it builds an SQL JOIN query, that pulls the object, and the additional content types all in just one query. Then the referenced objects are all hanging off of the main object in the form of, object.content-types.

So for instance, if you have a "Publication" content type, and each Publication has many "Paper" types, it would be resource intensive and slow to execute another query for each Paper just to pull in details for each one, especially in a listing of many publications. But if the papers were pulled in with one query, and you can automatically reference an array of papers with: $node->papers. That would be ideal...