This is probably a minor php matter: I'm trying to get Node Carousel to display images from a CCK image field. Although I've been able to modify the theme in other ways, I can't get images to work. (these are additions in the "function theme_nodecarousel_node($node, $name='')" section of the nodecarousel.module.

For example, this custom CCK text field will display:
$content .= '

'. l($node->field_f_carousel_tease[0]['value'], 'node/'. $node->nid) .'

';

However, this custom CCK image field will not:
$content .= '

'. l($node->field_f_carousel_img[0]['view'], 'node/'. $node->nid) .'

';

Any direction on this is greatly appreciated.

This is an amazing module - I can't wait to use it fully.

Comments

jcfiala’s picture

Status: Active » Closed (works as designed)

Hmm... Here's the problem - all I do on the nodes is load them - I don't tell them to build themselves ready for viewing. As such, the field_f_carousel_img[0]['view'] has no data in it.

I set up a similar situation with my own test code, and I find that what you probably want to do is to call node_build_content() on the node - I suggest taking a look at it's documentation or for node_view, which uses it.

Personally, with CCK Image fields, I always use imagecache for my images, so I was using theme('imagecache', 'thumbnail', $node->field_image[0]['filepath']); for my own testing. However, when I did the following, it worked fine:

<?php
$node = node_build_content($node, TRUE, FALSE);
$content .= l($node->field_image[0]['view'], 'node/'. $node->nid, array(), NULL, NULL, FALSE, TRUE);
?>

Note that I had to extend l out far enough to tell it that I was handing it HTML - otherwise it'll escape it all out for you.

verbidei’s picture

Thanks for your help on this. The imagecache concept makes a bit more sense now that you point it out.

edzhus’s picture

this one works for me:

in template.php


function phptemplate_nodecarousel_node($node, $name='') {
$content = '<div class="node-carousel-item">';
$node = node_build_content($node, TRUE, FALSE);
$content .= '<div class="hidden nid">'. $node->nid .'</div>';
$content .= '<div class="carousel-image">'. theme('imagecache', 'imagecache_preset', $node->field_image[0]['filepath']) .'</div>';
$content .= ''. l($node->field_intro[0]['value'], 'node/'. $node->nid) .''; 
$content .= '</div>';
return $content;
}

gav240z’s picture

I'm having trouble with this, seems to output everything but the filepath to the image correctly.
I'm using Drupal 6 though so maybe there's a change in the code or template.php I need to make.