How To Hide Empty Attribute In Magento?

On product detail page when Magento finds some attribute as an empty field, it shows “No” or “N/A”. You can hide those empty attributes by just edit your template file named as “attributes.phtml”. Just be sure that you are editing your own theme template file, better you use system “Template Path Hints”.

In my case it was /app/design/frontend/default/default/template/easytabs as I was using an extension. Default is /app/design/frontend/default/YOUR THEME/template/catalog/product/view/attribute.phtml. Now edit attribute.phtml file:

Find 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 these lines with this:

<?php foreach ($_additional as $_data): ?>
	<?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A'): ?>
		<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 endif; ?>
	<?php endforeach; ?>

OR

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

Thats it. Thanks to Hudony for easy solution.

13 Responses to How To Hide Empty Attribute In Magento?

  1. Sparc says:

    This doesn’t work for me, I’m using 1.7
    Is anybody having success?

  2. Kurt Hansen says:

    Thanks, worked nicely on 1.7.0.2 !

  3. AJ says:

    How would you edit this with the compare/list.phtml page?

  4. soni says:

    /app/design/frontend/default/YOUR THEME/template/catalog/product/view/attribute.phtml Use this path

  5. David Line says:

    This works for me as well. Thanks!

  6. hudony says:

    I came up with this :

  7. sidlo says:

    second solution works first doesn’t. Thank you :)

  8. Hi, Sorry if I follow that Path I don’t see file attribute.phtml what can I do in this case? I’m using Magento 1.8

    Should I create this file? and if I do so, what do I have to place there there?

Leave a Reply

Your email address will not be published. Required fields are marked *