I have posted this before, but that was before CCK got support for NULL entries.

Basically, I would like a CCK field to only show (along w/ its title) if the field has any text in it, otherwise it should be removed from the submission.

For example:

Source (title)

_______ (empty field)

With an example such as this I would like it to not be displayed.

Any help on this matter would be much appreciated, thank you for your time.

Comments

hazexp’s picture

Sorry for bumping, but is this possible?

sgriffin’s picture

?php if (!empty($item['view'])) { print "blah"....

Check into contemplate.

greeneo’s picture

How do I use that in here?

<?php foreach ((array)$field_pull_quote as $item) { ?>
  <div class="field field-type-text field-field-pull-quote">
    <div class="field-items">      
      <div class="field-item"><?php print $item['view'] ?></div>
	</div>
  </div>
<?php } ?>

That's what Contemplate gives me.

Rob_Feature’s picture

Usually contemplate starts by giving you a bunch of stuff you don't want. I'd suggest starting fresh and only putting in the stuff you want, complete with the if/thens that you need.

/**
  * Bob Christenson
  * Mustardseed Media
  * http://mustardseedmedia.com
  */
greeneo’s picture

Ok, how do I start fresh using this?

?php if (!empty($item['view'])) { print "blah"....
mariagwyn’s picture

greeneo (or someone) - did you every figure this out? I have a working node-cck.tpl.php file, but I need the php code to hide fields if they are empty, and I am not quite sure how to complete the "blah" suggestion above. Here is a sample field:

<?php if (content_format('field_subtitle', $field_subtitle[0]) > '') : ?>
  <?php foreach ($field_subtitle as $subtitle) { ?>
    <h4> <?php print content_format('field_subtitle', $subtitle) ?> </h4>
  <?php } ?>
<?php endif; ?>

How can I get this to actually hide or simply not display the empty field? - Thanks, Maria

elruy’s picture

i think this solution is better for hiding fields
http://www.tejasa.com/node/127

Boletus’s picture

Will this hide the field in all pages it can be shown, or just if I use views?

lias’s picture

This is from the link you posted. I tried putting it in field.tpl.php which has nothing but this code but the fields still displayed.

 // hide empty fields from display
if (!$items[0]['view']) return; ]

thanks.

dantina’s picture

In case it'll help anyone, check out post 1 of this thread: http://drupal.org/node/79188. Just checking if the field isset, NULL or blank doesn't seem to work. Referencing the field directly in the if statement didn't work well either (for some reason).

The following worked for me:

$trimmed_field = trim($node->field_cck_field[0]['view']);
if (!empty($trimmed_field)) { //do something wonderful .... }
RikiB’s picture

Thanks, that worked perfectly.