Reputation:
app/design/frontend/default/theme/template/catalog/product/view/attributes.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category design
* @package base_default
* @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
/**
* Product additional attributes template
*
* @see Mage_Catalog_Block_Product_View_Attributes
*/
?>
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<div class="fp1"><?php $Pro_name =$_product->getName();?>
<h2><?php echo $this->__('Specifications Of '."$Pro_name") ?></h2><br/><br/>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<?php if ($_data['code'] == 'gendernew'): ?>
<tr><th colspan="3"><?php echo $this->__('') ?></th></tr>
<th class = "tablehead" colspan="3" > GENERAL </th>
<?php elseif ($_data['code'] == 'productweight'): ?>
<tr><th class = "tablehead" id="prod_dim" colspan="3"><p style="background: rgb(255, 255, 255) none repeat scroll 0% 0% ! important; color: rgb(255, 255, 255); width: 100%; padding-top: 10px; padding-right: 10px; padding-left: 10px; padding-bottom: 0px ! important;" class="Product_dim">Product Dimension</p><?php echo $this->__('PRODUCT DIMENSION') ?></th></tr>
<?php endif; ?>
<tr>
<th class="label"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
<style>
.tablehead {
background-color: #f2f2f2;
font-weight: bold;
text-transform: uppercase;
font-weight:bold;
color:black;
}
</style>
this is the attributes.phtml file we are using to display the attibutes in frontend.
suppose if attribute value is empty , than thiose attributes will not display in frontend for the
particular product.
but if we give some empty space in the attribute text field, than those attributes are displaying in the frontend.
if we gave empty space as attribute values , than we want to hide those attributes for the particular product.
ex:
if attribute color = "" than color will not display in frontend
if attribute color = " " than color will display in frontend. we want to hide color here....
please help me to find solution....
Upvotes: 1
Views: 4584
Reputation: 941
Try using empty or trim function , something like this:
if(!empty($attributeValue)) { //replace $attributeValue with your variable name..
//do your thing
}
You can also check this - https://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
Update: Try changing this line
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
to
if (!is_null($_product->getData($_attribute->getAttributeCode())) && (trim((string)$_attribute->getFrontend()->getValue($_product)) != '')) { ?>
Hope this helps!!
Upvotes: 2