0

i am having problems hiding the label of the field in views if the field is empty when it accepts unlimited number of values. any idea how to resolve this? i tried this

 function alter_form_preprocess_views_view_fields(&$vars) {
   // Remove labels if value is empty.
   foreach ($vars['fields'] as $id => $field) {
     if (!$field->content) {
       unset($vars['fields'][$id]);
     }
   }
 }

it didn't work

4

1 回答 1

0

我所做的是为每个字段创建一个新字段作为标记,如果它没有任何值,我想隐藏它的标签,并为每个标记字段创建一个 tpl 文件并执行此操作:

<?php
    if(!empty($row->{node_data_field_d_a_name_field_d_a_name_value}[0]['value'])){
        print $output;
    }
?>

从技术上讲,它不是一个标签,但就像它一样工作,它解决了我的问题。

注意:我从每个字段中删除了标记和具有值的字段,这样我就不会为同一字段设置多个标签。

于 2012-12-03T09:26:18.757 回答