Magento – Magento 2 – show product attribute labels

magento-2.1product-attribute

I'm able to display product attributes values as follow:

app/design/frontend/Vendor_name/theme_name/Magento_Catalog/layout/catalog_product_view.xml

...

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.formato" template="product/view/attribute.phtml" after="product.info.sku">
  <arguments>
    <argument name="at_call" xsi:type="string">getManufacturer</argument>
    <argument name="at_code" xsi:type="string">manufacturer</argument>
    <argument name="css_class" xsi:type="string">manufacturer</argument>
    <argument name="at_label" xsi:type="string">manufacturer</argument>
    <argument name="add_attribute" xsi:type="string">itemprop="manufacturer"</argument>
  </arguments>
</block>

...

The code above will print the value (e.g, 64). How can I print the associated manufacturer's name (e.g, Ferrari)?

edit

My attribute.phtml is as follow:

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_call = $block->getAtCall();
$_code = $block->getAtCode();
$_className = $block->getCssClass();
$_attributeLabel = $block->getAtLabel();
$_attributeType = $block->getAtType();
$_attributeAddAttribute = $block->getAddAttribute();

if ($_attributeLabel && $_attributeLabel == 'default') {
    $_attributeLabel = $_product->getResource()->getAttribute($_code)->getFrontendLabel();
}
if ($_attributeType && $_attributeType == 'text') {
    $_attributeValue = ($_helper->productAttribute($_product, $_product->$_call(), $_code)) ? $_product->getAttributeText($_code) : '';
} else {
    $_attributeValue = $_helper->productAttribute($_product, $_product->$_call(), $_code);
}
?>

<?php if ($_attributeValue): ?>
    <div class="product attribute <?php echo $_className?>">
        <?php if ($_attributeLabel != 'none'): ?><strong class="type"><?php echo $_attributeLabel?>:</strong><?php endif; ?>
        <span class="value" <?php echo $_attributeAddAttribute;?>><?php echo $_attributeValue; ?></span>
    </div>
<?php endif; ?>

Best Answer

eureka! Just add:

<argument name="at_type" xsi:type="string">text</argument>

to the block's arguments.

Related Topic