In the node.tpl file for a new project, I am unable to hide an imagefield despite it being empty. My code is almost the same as that working on another site (a D5 site, different field_name and imagecache presets)

<?php if (!$teaser): ?> 
  <?php if ($node->field_leading_photogragh): ?> <!-- display CCK field 'leading photograph' -->
    <div class="leading_photograph">
      <?php print theme('imagecache', 'leading-image', $node->field_leading_photogragh[0]['filepath']); ?> 
    </div>
  <?php endif; ?>
<?php endif; ?>

[the typo in the field name is correct].

I have tested this exact code with a non-existent CCK field in the same tpl file and nothing is displayed (as expected). With the above code, the output is

<!-- display CCK field 'leading photograph' -->
<div class="leading_photograph">
  <img src="http://example.com/files/imagecache/leading-image/" alt="" title=""  class="imagecache imagecache-leading-image" /> 
</div>

Anyone able to suggest a reason why this is happening?

[using CCK 6.x.2.2]

Comments

quicksketch’s picture

Like other CCK fields, the field is still there even if it's empty. Instead of just checking if it's there, you should check if the filepath is set.

<?php if ($node->field_leading_photogragh[0]['filepath']): ?>

<?php endif; ?>
avolve’s picture

Status: Active » Closed (fixed)

@quicksketch thank you for this — resolved the issue.