if empty statements in views fields or field templates Normally, my situation is easily solved using views rewrite feature. However, in this case I am unable to use views rewrite because I have data attribute tags in the field wrappers that are stripped out by views. So I need to handle this at the template level. I have no problem with the field data itself, but with the field wrappers. I need to use php if statements in either views-view-field.tpl.php or views-view-field.tpl.php to enclose the wrapper html too along with the field. But i can't figure out the php syntax to use to accomplish this. I need to be able to show the field data plus wrappers if the field has content, but show some empty field without the wrappers if there is no data.

so far i have tried things like views-view-field.tpl.php

&lt;?php if ($output): ?&gt;
    &lt;p class="tms-caption font-alt-1 text-medium weight-light color-white hide-on-mobile mb-30" data-animate-in="preset:slideInDownShort;duration:900ms;delay:500ms;" data-no-scale&gt;&lt;?php print $output; ?&gt;&lt;/p&gt;
&lt;div class="clear"&gt;&lt;/div&gt;
  &lt;?php elseif ($empty($output)): ?&gt;
    &lt;div class="view-empty"&gt;
      &lt;?php print $empty; ?&gt;
    &lt;/div&gt;
  &lt;?php endif; ?&gt;


How can i revise my if statements to it works in either fields or field.tpl.php?
First of all, there is no such thing as $empty in views-view-field.tpl.php



Second, if you're not printing anything when the output is empty, then there is no need to add an else statement. Thus, this should do the trick:

&lt;?php if (!empty($output)) : ?&gt;
    &lt;p class="tms-caption font-alt-1 text-medium weight-light color-white hide-on-mobile mb-30" data-animate-in="preset:slideInDownShort;duration:900ms;delay:500ms;" data-no-scale&gt;&lt;?php print $output; ?&gt;&lt;/p&gt;
&lt;?php endif; ?&gt;


The first line means if NOT empty, in PHP ! = not.