Hi. I have a Drupal 6 site and I added an Image field to a content type using CCK. Now I'm creating a view on that content type. I want to mess with the image tag for the image field in my theme. I've used the preprocess function in template.php, and I've used template files as suggested by the Theme Information link in the view. I can get the data for the image just fine (alt, description, etc.) but not the URL, and not the thumbnail and preview URLs. I know how to modify an image node, but since the image field is just a field and not a node, I can't find a way to access the URL for the image. Some of my questions are:

Can I access the preview and thumbnail files for an image field the way I can for an image node?
Are there theme functions I can use to ask for the thumbnail and preview sizes of an image if I have the fid for the image?

And then the catchall question: What's the best way to theme CCK image fields in a view?

Thanks.

Comments

ckng’s picture

If you are using ImageCache, then you can always call theme('image_cache', 'thumbnail', $your_cck_image_fid) almost anywhere, where thumbnail is the imagecache preset you've defined.

It is usually done in Contemplate.

Or a more direct way is to theme the CCK image field. Use devel module to see the theme template suggestion or override the field template (outline in http://drupal.org/node/269319#comment-1184661)

native.human’s picture

Thanks. On your recommendation I'm working with imagecache, which sounds like it will work. I installed imagecache, enabled it along with the UI, and added a preset to my CCK image field. How do I tell it to build the derivatives for all the existing nodes?

ckng’s picture

There is no need to do so, it will dynamically create it when it cannot find it, i.e. if the image is not generated yet, they will generate it and cache it.

native.human’s picture

Thanks. I wasn't seeing the derivative images, and it turned out I didn't have ImageMagick installed. Now I do, and it all works as advertised. Thanks again.

rimian’s picture

The only problem with theming imagecache is that the full CCK field is not available for theming.

webkenny’s picture

In case anyone happens upon this and is confused as I was, the function being referred to here is actually: theme_imagecache($namespace, $path, $alt = '', $title = '', $attributes = NULL)

Where $path can be the fid of the image or the URL to it.

Kenny S.
Follow me on Twitter

Andric Villanueva’s picture

webkenny, THANK YOU! That was 3 days of work that I couldn't figure out.

The namespace is the preset that you've created and works like a dream. Pass it the actual path as the fid doesn't work

http://drupalcontrib.org/api/function/theme_imagecache/6

sethcohn’s picture

Thanks, found this page, and didn't scroll down at first. Wish I had, would have saved me a few minutes of wondering what was up with the bad code.