PHP条件语句显示一个字段

I have inserted a code to display product attribute in view.phptml, which works fine. But it shows a empty box, even when the field is empty.

The code I used to display is like this

<div class="add-to-box">        
<div class="add-to-cart"><div>image path</div>
<h3><?php
echo $_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift')
?></h3></div></div>

How I can add a condition to above statement to hide the empty box from display when the field is empty.!

Use either empty or is_null, like so:

<?php
    if( !empty( $_product->getFreeGift() ) ){
?>

... HTML here ...

<?php
    }
?>

or

<?php
    if( !is_null( $_product->getFreeGift() ) ){
?>

... HTML here ...

<?php
    }
?>

Hi may be you can use this

<?php 
if (isset($_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift'))) {
echo('<div class="add-to-box">        
         <div class="add-to-cart">
         <div>image path</div>
          <h3>'.$_helper->productAttribute($_product, $_product->getFreeGift(), 'free_gift').'</h3>
          </div>
      </div>');
} else {
   ..... // other stuff
}

The isset function here help to know if a variable contain something usefull. good work !