Hello,
Could someone help me please ?
I looking for a way to test the value of a field. If an image field is empty, i'd like to display another field.

Here's what I have in output, but it doesn't work.

<?php
if ($row->field_eve_image_fid>0) {
$destitle = $row->field_eve_image_fid;
}

else {
$destitle = $row->field_event_date_value;

}
return $destitle;
?>

Thank you very much.

Comments

drupalerocant’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

Hello,
This is what i did to sort it out. What i have is an image preview of a video (field_field_exp_video[0][rendered]['#markup']) to display in case the user did'nt upload a thumbnail for this video (field_field_exp_thumbvideo[0][rendered]['#markup']). This is the code I used for Views PHP 7.x-1.x-dev in the output code:

<?php
$thumb = $data->field_field_exp_thumbvideo[0][rendered]['#markup'];
$video = $data->field_field_exp_video[0][rendered]['#markup'];
if(empty($thumb)){
 print $video;}
else print $thumb;
?>

I hope it helps!

drupalerocant’s picture

Sorry!
Previous code was not correct!
This is the code I use now, without any warnings at the moment:

<?php
if(isset($data->field_field_exp_thumbvideo[0]['rendered']['#markup'])){
     $thumb= $data->field_field_exp_thumbvideo[0]['rendered']['#markup'];
}
if(isset($data->field_field_exp_video[0]['rendered']['#markup'])){
     $video=$data->field_field_exp_video[0]['rendered']['#markup'];
}
if(!empty($thumb)){
    print $thumb;
}  elseif (empty($thumb) && !empty($video)){
      print $video;
  }
   else{
     print 'NO SET ANY VIDEO';
  }
?>
johnv’s picture

Status: Active » Fixed

solved?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.