0

I have function in template.php which check if image fields exists (has content) and it adds classes if image exists (has_field) and if image does not exist (has_no_field).

This function now works with Unformatted format, but I need it to work with HTML list format. I already tried it with function theme_views_pre_render(&$view) but could not get it to work.

function theme_preprocess_views_view_unformatted(&$vars) {
  $view = $vars['view'];
  $rows = $vars['rows'];

  foreach ($vars['view']->result as $id => $row) {

    if (!empty($row->field_field_image) || !empty($row->field_field_image_2) || !empty($row->field_field_image_3)) {
      $vars['classes_array'][$id] .= ' has_field';
    }  
    else {
      $vars['classes_array'][$id] .= ' has_no_field';
    }
  }

}

How to make this work with HTML list format?

1

I think the hook name you are looking for is template_preprocess_views_view_list that applies to HTML list views.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.