开发者

How to output attribute name in magento?

I want to echo attribute name, but instead this is outp开发者_StackOverflowutting array for a dropdown.

<ul class="tabs">
    <li><a href="#tab1">Details</a></li>
     <?php if($this->getChildHtml('additional')): ?><li><a href="#tab2"<?php echo $_product->getAttributeText('keyingredients') ?></a></li><?php endif; ?>
<?php if ($_product->getData('keyingredients')): ?>         
    <?php echo $_product->getAttributeText('keyingredients') ?><li><a href="#tab5">Key Ingredients</a></li><?php endif; ?>
    <li><a href="#tab5">Product Tags</a></li>
    <li><a href="#tab6">Reviews</a></li>
</ul>

So what is the correct code to just display attribute name, rather than array?

This is creating an array :

<?php echo $_product->getAttributeText('keyingredients') ?>


To output the value of each entry in the returned array, use the following:

<?php foreach ($_product->getAttributeText('keyingredients') as $keyIngredient): ?>
    <?php echo $keyIngredient; ?>
<?php endforeach; ?>

If you want the name of the attribute keyingredients (Key Ingredients I would imagine) then use:

<?php echo $_product->getResource()->getAttribute('keyingredients')->getFrontendLabel(); ?>

See Magento: How to get attribute name and value? for more examples.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜