Using CCK + Contemplate + Imagefield + Imagecache / Need advice to improve

faunapolis - December 6, 2006 - 14:58

Ok, after reading many many forum posts I got it to work! well, almost:

First, what works:

CCK (Content Creation Kit) module: With this module you can create your own type of nodes. I installed this a long time ago together with Imagefield.
Imagefield module: Allows you to add an "Add image" field to your new type of node created with CCK. I recently changed it so that it could allow for more than one image!... and no need to add several image fields, one collects many images for you.
Image cache module: This module worked right away when I installed it. What I found difficult was not getting it to work, but knowing it was working. I found out it was working when a cached image worked. I also found out that it only created the elusive "imagecache" directory when the first image was cached, and that only happened when the image was rendered inside from the contemplate "teaser" template (I am copying the code below).
Contemplate module: With this module you can format your newly created CCK to appear differently when inside the main page, than when by itself.

This is the code for the teaser image (I put it together from: http://drupal.org/node/84958):

<div class="field field-type-image field-field-photograph--image">
  <div class="field-items">
     <?php foreach((array)$field_photograph__image as $item){print '<a

href="'
.$item['filepath'].'"><img src="/files/imagecache/animal_thumb/'.$item['filepath'].'"></a>';}?>

  </div>
</div>

Where:
photograph__image is my image field created using CCK, and
animal_thumb is the image modification or "preset" created using the imagecache module (administer>>imagecache)

What I still need to do:

1. I would love if every images to point to the specific node that they belong to; right now they are pointing to the 'filepath' or to the original image. I tried the variable $node_url didn't work because it points to the displayed node only (if in the frontpage, it points to the frontpage)
2. That the "alternate text" and "image title" are incorporated into the image... but I don't know what the variables are.
3. I can't see the "preset" options in my "custom" photograph__image field in the "Views" module so I can add the "thumb" to my geolocations map.

This is the site: faunapolis.org; by the way, it is working right now, but it might not be anymore if I keep on playing with it:). Can anybody help me with these "wants"?

Also, I'm very thankful to the drupal community; I am actually using drupal as a path to learning PHP!

1. I would love if every

quicksketch - December 6, 2006 - 17:44

1. I would love if every images to point to the specific node that they belong to; right now they are pointing to the 'filepath' or to the original image. I tried the variable $node_url didn't work because it points to the displayed node only (if in the frontpage, it points to the frontpage)

Good question. I'm assembling a series of patches right now to accomplish this task using views. So you'd be able to say select an image, display as thumb, and link to the containing node. It depends on where you're putting the code you posted. If you're using contemplate, it might be available as just $nid, but I'm not quite sure. To link to the parent node you should use

<?php
 
print '<a href="' . url('node/' . $nid) . "; //...finish the <a> tag
?>

2. That the "alternate text" and "image title" are incorporated into the image... but I don't know what the variables are.

Try (to use the built-in imagecache theme function - recommended):

<?php
foreach((array)$field_photograph__image as $item){
print
theme('imagecache', 'animal_thumb', $item['filepath'], $item['title'], array('alt' => $item['alt']));
}
?>

Or just use (since you're using contemplate):

<?php
foreach((array)$field_photograph__image as $item) {
print
'<a href="'.$item['filepath'].'"><img src="/files/imagecache/animal_thumb/'.$item['filepath'].'" title="'.$item['title'].'" alt="'.$item['alt'].'"></a>';
}
?>

You may not be aware of the function print_r which dumps out the contents of a variable so you can see what to use. You'll also find the devel.module very helpful for debugging. If you have devel module, you can use my favorite function 'dsm()' which prints the contents of a variable to the drupal message area, nicely formatted.

3. I can't see the "preset" options in my "custom" photograph__image field in the "Views" module so I can add the "thumb" to my geolocations map.

Wish I could help here. Those presets should exist in Views.

Nathan Haug
creative graphic design        w: quicksketch.org
& software development       e: nate@quicksketch.org

Hard reset for content templates (Contemplate)?

faunapolis - December 6, 2006 - 21:17

QuickSketch,

This has actually been very very helpful. I got it to work almost perfect, but while trying to do this, I caused an error which doesn't let me go in and reset my main node template.

The error is:
Fatal error: Call to undefined function: array() in /home/faunapol/public_html/modules/contemplate/contemplate.module(455) : eval()'d code on line 23

It comes up even when I click on the "edit template" link.

Thanks

Fixed it, thanks

faunapolis - December 6, 2006 - 21:29

Went into the mySQL and copied the previous version of my template into the record/field!

Thanks

http://www.faunapolis.org/

Imagefield in Views

faunapolis - December 12, 2006 - 16:08

Thank you very much for the help, the site is looking sharp. I don't even want to look at the administrator pages so that I don't break it down again.

The option to place thumbs as a field in the "add fields" section of the views menu (what a bunch of words) only came up after I loaded the new CCK imagefield module + ran the update.php script (hope this helps anyone with the same problem).

http://www.faunapolis.org/

 
 

Drupal is a registered trademark of Dries Buytaert.