Magento: hide dropdown attribute if value

I am using this code to hide attributes when they have no data:

<?php foreach ($_additional[ 'items'] 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; ?>

      

This works great, but not for the dropdown of attribute types.
How can I hide the attributes of the dropdown that are irrelevant?

+3


source to share


1 answer


If the dropdown attribute is not set, it usually appears as N/A

in the front end of your website, so you can simply add && $_data['value'] != 'N/A'

inif-statement

So, the code will look something like this:



<?php foreach ($_additional[ 'items'] as $_data): ?>
     <?php $_attribute = $_product->getResource()->getAttribute($_data['code']); if (!is_null($_product->getData($_attribute->getAttributeCode())) && ((string)$_attribute->getFrontend()->getValue($_product) != '' && $_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 } ?>
<?php endforeach; ?>

      

+1


source







All Articles