Magento 2.0.1 – Render Dropdown from Product Dropdown Attribute

magento2productproduct-attribute

I have created one drop down attribute, I followed this tutorial to get selected values from that attribute. I successfully get the result, But I want to render whole drop down.What I do for achieve this?

Best Answer

On Product Detail Page or on Product List Page you can get attribute (color replace with yours) drop down value using following code:

<?php 
$attr = $_product->getResource()->getAttribute('color')->getOptions(); 
foreach ($attr as $attrColor) {
    echo $attrColor->getValue();
    echo '<br>';
    echo $attrColor->getLabel(); 
}           
?>
Related Topic