Hi, I am having an Issue with linked Imagefields in Zen.

Even if there are no images loaded there are empty fields printed with a border and the node's title (shown on the screenshot: http://img15.imageshack.us/img15/194/fireshotcapture25artist.png).

At first, i thought it was a filefield/imagefield module malfunction and posted it here:
http://drupal.org/node/414944

The problem was considered not reproducable and so i built the site from scratch from an all fresh core and modules - this is what I am using (the only thing i used from the old site is the zen-subtheme):

---
Drupal 6.10
Content Construction Kit (CCK) 6.x-2.2
FileField 6.x-3.0
ImageField 6.x-3.0
ImageCache 6.x-2.0-beta9
Lightbox2 6.x-1.9

Zen sub-theme based on 6.x-1.0

2 imagecache presets: one for a partial preview image, another for the fullsize image (which is beeing linked to the preview via lightbox2)
---

I tested the filefields in the garland theme and here, they behave normal. So the problem of empty fields still showing must be related to my node.tpl.php syntax. This is what I use:

<?php
// Format the teaser image
if ($field_image_standard_thumb) {
  $image_standard_thumb = theme('imagecache', 'desaturate_-_resize_182px-110px', $field_image_standard_thumb[0]['filepath'], $node->title, $node->title);
}
?>

<div class="node">

	<?php // Teaser view
		if ($teaser): ?>
			
			<!-- Headline with link to node, followed by meta information (submitted and tags). 		
			<h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>

			<div class="meta">
			
			<div class="meta">
				<span class="submitted"><?php print $submitted ?></span>
				<?php if ($terms): ?>
					<span class="terms"> in <?php print $terms ?></span>
				<?php endif; ?>
			</div>
			-->
			
			<div class="content">

			<?php if ($image_standard_thumb): ?>
				<!-- Div wrap with class for the nodelink.
				<div class="field field-type-image field-field-image-standard-thumb imagefield-nodelink">
				-->
				
				<div class="field field-type-image field-field-image-standard-thumb imagefield-gallerylink">
					<div class="field-items">
				
						<!-- Print the teaser image as a link to the full node.
						<?php
						print l($image_standard_thumb, 'node/'. $nid, array('html' => 'TRUE')) ?>
						-->

						<div class="field-item odd">
						<?php // Print the teaser image and link it to the fullsized image.
						print l($image_standard_thumb, imagecache_create_url('scale_500px_max', $field_image_standard_full[0]['filepath']), array('html' => 'TRUE', 'attributes' => array('class' => 'imagefield-field-image-standard-thumb', 'rel' => 'lightbox[]', 'title' => $node->field_image_standard_full[0]['data']['title']) ) ); ?>

						</div>
					</div>
				</div>
			<?php endif; ?>

			<?php print $node->teaser ?>
			
			<!-- Other content here -->

			</div>

	<?php // Full view
		else: ?>
			
			<!-- Meta information (submitted & tags).
			<div class="meta">
				<span class="submitted"><?php print $submitted ?></span>
				<?php if ($terms): ?>
					<span class="terms"> in <?php print $terms ?></span>
				<?php endif; ?>
			</div>
			-->
			
			<div class="content">

			<?php if ($image_standard_thumb): ?>
				<div class="field field-type-image field-field-image-standard-thumb imagefield-gallerylink">
					<div class="field-items">
						<div class="field-item odd">
						<?php // Print the teaser image and link it to the fullsized image.
						print l($image_standard_thumb, imagecache_create_url('scale_500px_max', $field_image_standard_full[0]['filepath']), array('html' => 'TRUE', 'attributes' => array('class' => 'imagefield-field-image-standard-thumb', 'rel' => 'lightbox[]', 'title' => $node->field_image_standard_full[0]['data']['title']) ) ); ?>
						</div>
					</div>
				</div>
			<?php endif; ?>

			<?php print $node->content['body']['#value'] ?>

			<!-- Other content here -->

			</div>

	<?php endif ?>

</div>

And this is the relevant HTML output for an empty field still displayed:

<div class="field field-type-image field-field-image-standard-thumb imagefield-gallerylink">
<div class="field-items">
<div class="field-item odd">
<a class="imagefield-field-image-standard-thumb lightbox-processed" title="" rel="lightbox[]" href="http://wp1121964.wp021.webpack.hosteurope.de/sites/default/files/imagecache/scale_500px_max/">
<img class="imagecache imagecache-desaturate_-_resize_182px-110px" title="Mimaku Spldat" alt="Mimaku Spldat" src="http://wp1121964.wp021.webpack.hosteurope.de/sites/default/files/imagecache/desaturate_-_resize_182px-110px/"/>
</a>
</div>
</div>
</div>

The problem is that the tpl.php is creating an Only local images are allowed. path that ends where the actual file would be placed. Also i wonder why the alt text of the empty field prints the node title - i'd prefer to use the field's default alt text.

How would i have to modify the tpl.php to make the separate images still link via lightbox but only display when theres actually content to be displayed?

Comments

johnalbin’s picture

Status: Active » Closed (won't fix)

This is definitely not Zen related. Your node.tpl.php is at fault.

Looking at your call to imagecache_create_url() I see the answers to each of your questions. Why is the HTML output like it is? Because you told imagecache_create_url to do it that way (you haven't specified an alt value, you're not giving it the name of the file, just the path to the file). In addition, the function sounds wrong to me (like you are using the wrong part of the API), but I'm not familiar with the imagecache API to say for sure.

Also, you might want to learn about preprocess functions. Tpl files are not good places for complex PHP.

mimhakkuh’s picture

Thx for the feedback, John. Will have a look at it again after studying the prep. functions ...

RobW’s picture

Did you solve this? I'm having a similar issue. I assume it's a problem with my understanding of the "if ($imagefield_name) {" variable choice. Maybe ask if the imagefield path has a value? I don't know, beginner here. Thanks.

mimhakkuh’s picture

due to lack of time and complexity of preprocess functions, i couldnt fix this yet ... until this is fixed, the imagefields will remain as required fields ;( ...

RobW’s picture

OK, figured something out that seems to work in my case. It looks like that when you have an imagefield available in a content type the field variable is still present even if you haven't uploaded anything to it, so if ($my_field_name) { will return true no matter what. I used a check for a variable that is only present when an image is uploaded, namely filepath, and that worked. The code I'm using is if ($node->field_main_image[0]['filepath']) :

I'm also an amateur Drupal themer so this may not work for all applications. Devel was essential in figuring this out, as well as copying other examples' syntax for selecting variables. If anyone has a good resource about how to select variables in Drupal I'd be grateful to have a link.