I am using magento version 1.9 and I need to hide description block if no data found, if data exits the block shows description, if not found, that should be hide.
-
Which magento version you are workingon?– Nitin PawarNov 15, 2016 at 4:38
-
magento : 1.9.2.3– GemNov 15, 2016 at 4:38
-
1find the file which returns the product description there you can write the condition to check empty field.– Nitin PawarNov 15, 2016 at 4:42
2 Answers
Go to product view page
app/design/frontend/Your-namespace/Your-theme/template/catalog/product/view.phtml
Put your description block code between below condition:
if($_product->getDescription()){
//description block goes here
}
-
-
-
-
-
1app/design/frontend/Your-namespace/Your-theme/template/catalog/product/view.phtml Nov 15, 2016 at 4:52
The file can be found here:
/app/design/frontend/[theme name]/[package name]/template/catalog/product/view/attribute.phtml
Open the file and search for the following lines:
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr><?php endforeach; ?>
Replace the entire foreach loop with the following lines of code:
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
<?php foreach ($_additional as $_data): ?>
<?php $_attribute = $_product->getResource()->getAttribute($_data['code']);
if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '')) { ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php } ?>
<?php endforeach; ?>
You can find here: Hide attributes with no value
-
-
2
-