Question

In a module of mine, I'd like to output the node teaser. The node has CCK fields, and I'd like them to be displayed accordingly to the visibility settings you can choose in the content types / field settings administration area.

But when I do:

$html = theme('node', $n);

the resulting teaser won't contain the CCK fields, only title and body.

What other theming function do I need to call?

The node contains fields such as an image and a node reference. I suppose I could write the HTML manually, but it seems to me better to use the provided theming functions...

Was it helpful?

Solution

http://api.drupal.org/api/function/node_view/6

$node = node_load($n);
$html = node_view($node,TRUE);

Then you can select the fields to display on Content Type>Display Fields after that, you can edit the theme of that teaser via contemplate module or node-content_type.tpl.php on the theme folder.

OTHER TIPS

http://drupal.org/node/362068#comment-1216250 you can achieve it using views 2

Additionally using node_view from code allows a total of 4 node template modes.

node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)

For crazy nodes I've had my template like this...

<?php
switch(true){
case($page && $teaser): ?>

  <div class="content">
    <?=$content?>
  </div>

<?php
break;
case($page && !$teaser): ?>

  <div class="content">
    <?=$content?>
  </div>

<?php
break;
case(!$page && $teaser): ?>

  <div class="content">
    <?=$content?>
  </div>

<?php
break;
case(!$page && !$teaser): ?>

  <div class="content">
    <?=$content?>
  </div>

<?php
break;
default: print 'this should never happen.';
}?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top