Magento – Echo product attributes elsewhere on product page in Magento 2

attributesmagento2PHPproduct

Currently working on a Magento 2 build, and I've been stumped by something I guess is probably pretty simple.

As it stands, product pages are pretty much default, and product attributes are shown in the 'More Information' tab at the bottom.

What I'm attempting to do is echo an attribute's value elsewhere on the product page.

Since by default it seems to pass all the values to the page, I'm guessing there's simply a piece of syntax I'm missing for calling it in one of the product page view files.

I've tried a few things, such as:

$_product->getAttributeText('discount_banner');

But they seem to be the syntax for Magento pre-2.0.

If anyone can help out with what I'm doing wrong, I'd be incredibly appreciative.

Best Answer

You can achieve this all through your catalog_product_view.xml. I had to spit out some attributes just below the breadcrumbs of the product view using the following.

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.manufacturer" template="product/view/attribute.phtml" after="product.info.item">
    <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" translate="true" xsi:type="string">default</argument>
        <argument name="title" translate="true" xsi:type="string">Overview</argument>
        <argument name="add_attribute" xsi:type="string">itemprop="manufacturer"</argument>
    </arguments>
</block>
Related Topic