How to modify a field value in field--field_myfield.tpl.php in Drupal 7
Question
I'm trying to hide a field and the field label if the value of the field is '0' using the field--field_start_time.tpl.php override method. My template file logic is as follows.
<?php if ($element['#object']->field_start_time != '0')): ?>
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:
</div>
<div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print
$item_attributes[$delta]; ?>><?php print render($item); ?></div>
<?php endif; ?>
This is causing chaos with my node render and is obviously wrong. Any help would be GREATLY appreciated. Thanks.
Solution
After starting out with Drupal 4 I continued because the community support was awesome.. However after waiting over a day for no answer on drupal.org nor here on what is really a simple question with really awful documentation, I guess I can conclude those days are over.
following code in node.tpl.php
if ($content['field_start_time']['#items']['0']['value'] == '0') {
hide($content['field_start_time']);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow