Hello. Ias it possible, to stop node headings appearing on a published node if there is no value submitted.

Here is a real life example on my site. On the page I have not submitted a 'least favourite track' or 'for fans of'. Can I make those headings not show up?
http://allcdreviews.com/node/4

Thank you

Comments

geraldferguson’s picture

Are you using contemplate? I think this would require some logic to detect if a value has been entered. If not, then just don't show that heading, or hide it using CSS.

eviljoker7075’s picture

ok, first of all what is contemplate? I assume it's sme sort of module, if so, will it affect the template I already have installed?

Secondly where would I enter the logic statement?

mooffie’s picture

locate yout theme directory (it should contain 'page.tpl.php'). Create a 'template.php' file and in it put the following:


// We override CCK's theme_field() to not print the field's header unless the field isn't empty.

function phptemplate_field(&$node, &$field, &$items, $teaser, $page) {
  $output = '';

  $output .= '<div class="field field-type-'. strtr($field['type'], '_', '-') .' field-'. strtr($field['field_name'], '_', '-') .'">';

  if ($items && ("{$items[0]['view']}" != '') ) { // our modification is this 'if' clause.
	$output .= '<h3 class="field-label">'. $field['widget']['label'] .'</h3>';
  }

  $output .= '<div class="field-items">';
  foreach ($items as $item) {
    $output .= '<div class="field-item">'. $item['view'] .'</div>';
  }
  $output .= '</div>';

  $output .= '</div>';

  return $output;
}

eviljoker7075’s picture

Will this totally override the template field in the contemplate module? Because I am using that... is there some simple IF statement I could add to the template field in Administer>>content types>> templates?

An example field name I use is:
$field_for_fans_of

mooffie’s picture

The solution I provided has nothing to do with the contemplate module. Using the contemplate module is another solution, and it has some drawbacks, e.g. you have to update the 'template' whenever you add fields to your content type, and you have to create a 'template' for each of your content types.

My solution looks more complicated, but IMHO it's actually the simpler and easier.

Will this totally override the template field in the contemplate module?

The other way around: contemplate overrides the function I gave you.