Checking if a node has no content?

ltwinner - September 24, 2009 - 12:18

I'm using CCK (Content Profile) for my user profiles. Basically I need to check if there is no data entered into any of the fields yet and if that is the case I want to display text saying for example "John has not created his profile yet" in place of the node. How could I go about checking if all the fields of the node, regular fields and cck fields, are empty?

You could create a view which

adam_b - September 24, 2009 - 14:53

You could create a view which uses a filter that tests whether particular fields are empty or not. However, I'm not sure how you'd get to the next step of displaying the alert you want.

I don't really want to use

ltwinner - September 24, 2009 - 15:34

I don't really want to use views as its adding another layer of complexity to the whole thing. I'm thinking there must be a simple for loop that can be written that will cycle through the fields and set a "no_fields" flag if they are all empty. And then if "no_fields" is set, output the "John has not created his profile yet" text, otherwise output the node as usual.

Anyone familiar with cck code able to tell me how to write that for loop and save me a few hours familiarising myself with the cck code?

I'm interested in this

johnlee80 - October 1, 2009 - 01:06

I'm interested in this function as well. Haven't had any luck yet..

Well here's how I did it. You

ltwinner - October 4, 2009 - 16:59

Well here's how I did it. You can simply check the node to see if the CCK fields are set. This is im my user-profile.tpl.php file.

  $node = NULL;
  $node_profile = $content_profile->get_variables('profile');
 
  if ($node_profile)
    $node = &$node_profile['node'];

  if (empty($node['field_name_1'] &&
      empty($node['field_name_2'] &&
      empty($node['field_name_3']){
  print "This user has not created their profile yet";
  }

 
 

Drupal is a registered trademark of Dries Buytaert.