2012-03-22 6 views
0

view.phptml에 제품 속성을 표시하는 코드를 삽입했는데 제대로 작동합니다. 그러나 필드가 비어 있더라도 빈 상자가 표시됩니다.필드를 표시하는 PHP 조건문

I 표시하는 데 사용되는 코드처럼이

<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> 

필드가 비어있을 때 나는 화면에서 빈 상자를 숨길 수 위의 진술에 조건을 추가 할 수있는 방법.!

+1

간단한 'if-else' 문이 작동하지 않았습니까? – hjpotter92

답변

2

사용 중 empty 또는 is_null, 그래서 같은 :

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

... HTML here ... 

<?php 
    } 
?> 

또는

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

... HTML here ... 

<?php 
    } 
?> 
+0

대단히 Tieson T. 감사합니다. 예상대로 작동했습니다. – Joshi

0

안녕하세요 당신이 알고 여기에 도움이

<?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 
} 

isset 기능을 사용할 수 있습니다 될 수있다 변수는 유용한 것을 포함합니다. 잘 했어!