1

I have code which checks if field exists, but I try to change it to check if field has value (content) or not.

In views I have one field to show all content (Rewrite results). So all fields are loaded always. Thats why I need code which checks does field have content or not.

This is what I got now, but it adds "has_no_field" to all - no matter if field_image has content or not.

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

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

    if (isset($row->field_image['und'][0]['value']) == 1) {
      $vars['classes_array'][$id] = 'has_field';
    }  
    else {
      $vars['classes_array'][$id] = 'has_no_field';
    }
  }
}

1 Answer 1

5

Try changing

if (isset($row->field_image['und'][0]['value']) == 1) {

to

if (!empty($row->field_field_image)) {
2
  • Still adding "has_no_field" to all rows - no matter if there is image or not.
    – hene
    Commented Jul 31, 2014 at 12:28
  • @hene I've updated the answer. Observe the extra field_ in front of field_image. Had to have a look myself and just noticed that :) Commented Jul 31, 2014 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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