Remove CCK field from a view using template file
This is how to remove a CCK-field with a special condition. If you just want to hide the field in hull node and/or teaser view you can configure it at Manage fields / Display fields at your content type.
Don't forget to refresh your them registry before testing, otherwise you wont see any difference. If you are using the admin menu module ( http://drupal.org/project/admin_menu) you find it in the first menu, Flush all cashes /Theme registry.
Create a file, content-field.tpl.php, in your theme folder.
Add the following content to this file:
<?php
// $Id: content-field.tpl.php,v 1.1.2.5 2008/11/03 12:46:27 yched Exp $
/**
* @file content-field.tpl.php
* Default theme implementation to display the value of a field.
*
* Available variables:
* - $node: The node object.
* - $field: The field array.
* - $items: An array of values for each item in the field array.
* - $teaser: Whether this is displayed as a teaser.)
* - $page: Whether this is displayed as a page.
* - $field_name: The field name.
* - $field_type: The field type.
* - $field_name_css: The css-compatible field name.
* - $field_type_css: The css-compatible field type.
* - $label: The item label.
* - $label_display: Position of label display, inline, above, or hidden.
* - $field_empty: Whether the field has any valid value.
*
* Each $item in $items contains:
* - 'view' - the themed view for that item
*
* @see template_preprocess_field() in D7...
*/
if ($node->type == "clinical_indication" AND $field_name == "field_indication_belongings" AND ADDITIONAL_CONDITION) {
//Remove field
}else{
?>
<?php if (!$field_empty) : ?>
field-<?php print $field_name_css ?>"> <?php if ($label_display == 'above') : ?>
<?php print t($label); ?>:
<?php endif;?>
<?php $count = 1; foreach ($items as $delta => $item) : if (!$item['empty']) : ?>
"> <?php if ($label_display == 'inline') { ?>
"> <?php print t($label) ?>:
<?php } ?> <?php print $item['view']; ?>
<?php $count++; endif; endforeach;?>
<?php endif; }
?>Knowledge keywords:
