I'm using Drupal 5 & 6 wth CCK. Any idea how I can show CCK field labels even when there's no content in the field in that particular node? For example, I have a CCK for 'cars' and create fields for make, model, engine size. If I then create a node for a Volkswagen Golf, where I don't know the engine size, the page will render something like:

Make: Volkswagen
Model: Golf

With the engine size label missing. I would like it to show:

Make: Volkswagen
Model: Golf
Engine:

So now other viewers can see what's missing when they're viewing the page, and then they're more likely to click 'edit' to fill in the blanks. Is there a simple solution without having to create templates for the page? Possibly just a change in CSS? Something that would work for both Drupal 5 & 6 would be great

It looks like CCK used to show empty fields, but it was taken out because some people didn't want to show labels on empty fields. Would be good if it were optional via something like CCK display fields

Thanks

Stuart

Comments

Roulion’s picture

you can use Content Templates (http://drupal.org/project/contemplate) to make this work.. It's the best solution i think

StuartDH’s picture

I agree that contemplate is good, but I think it's a bit of an overkill for jut showing empty field labels. If you use contemplate you have to rebuild the template, style it, add new field labels and field values every time they're created in the content type etc.

Would be great if some simple css or a dropwon in the cck content type could swtich on to show labels when the fields are empty

Fayna’s picture

I'm looking for something similar, where a default text like "nothing added yet" or a link to edit the node next to the label could be displayed when a field is empty. I couldn't find any snippets on how to accomplish this and I'd rather not use Contemplate.

yched’s picture

Easiest way right now is to override content-field.tpl.php in you theme.
Install Advanced help module and check the 'Theming CCK data in nodes / Field templates' section for more information if you're not familiar with templates overrides in D6.

You'll see that the default content-field.tpl.php template starts with

<?php if (!$field_empty) : ?>
(...)
<?php endif; ?>

You simply want to remove that enclosing test.

tlogan’s picture

This works fine but I'd love to see this as an option per content type or by field.

gintass’s picture

I agree with tlogan. Especially since we already do have an "Exclude" check-box on CCK's Display Fields page which allows us to hide any field from the teaser or the full view even if the field does have a value. How nice it would be to have an "Include" check-box which would allow us to display field even if does not have any value? I would say in many cases it would make much more sense to display ALL the fields by default. If someone doesn't like that they could click "Exclude" check box, which we already have. Following that logic to make it totally flexible it would have to be another column with check-boxes called "Exclude if empty" or something like that. This would allow to create a current behavior - hide fields that have no values.

I also found this thread which suggests that this type of behavior would be in sync with the logic that already exists:
http://drupal.org/node/624198

I assume that until this is rectified we just have to follow suggestion in comment #4.

markus_petrux’s picture

Category: feature » support
Status: Active » Fixed

As a support request, this is fixed by explanation in #4.

As a feature request, this is won't fix unless someone else comes up with a patch for review, the patch is reviewed by other users, and etc.

gintass’s picture

@markus_petrux - Thank you, understood.

BTW in the current version of CCK there are two tests "if !empty" therefore you need to comment/remove both. The second one starts on line 36:

 if (!$item['empty']) : ?>
(...)
    endif;
markus_petrux’s picture

Not the same thing. $field_empty is TRUE if all possible values of the field are empty, on the other hand, $item['empty'] refers to a single value. Think about multiple value fields.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

TheodorosPloumis’s picture

I tried to do the solution from #4 but nothing happens! I cleared all caches but the field label still not displayed. Am I doing something wrong?

LiloLilo’s picture

Modify content-field.tpl as follows:

<div class="field field-type-<?php print $field_type_css ?> field-<?php print $field_name_css ?>">
  <?php if ($label_display == 'above') : ?>
    <div class="field-label"><?php print t($label) ?>:&nbsp;</div>
  <?php endif;?>
  <div class="field-items">
    <?php $count = 1;
    foreach ($items as $delta => $item) :
      if (!$item['empty']) : ?>
        <div class="field-item <?php print ($count % 2 ? 'odd' : 'even') ?>">
          <?php if ($label_display == 'inline') { ?>
            <div class="field-label-inline<?php print($delta ? '' : '-first')?>">
              <?php print t($label) ?>:&nbsp;</div>
          <?php } ?>
          <?php print $item['view'] ?>
        </div>
      <?php $count++;
	  else: ?>
	    <div><?php print 'Not specified'; ?></div>
      <?php endif;
    endforeach;?>
  </div>
</div>