0

I need to display a custom attribute bellow the product name and I don't know how can I call this attribute.

I am editing the file /app/design/frontend/templatemela/MAG100219_1/template/catalog/product/view.phtml But how can I call this attribute in php? I tried calling a string echo with the name I put in the attribute, but it didn't work.

Code is as below:

<div class="page-title product-title"> 
<h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
</div>

<div class="codigoinmetro"> 
<h2><?php echo $_helper->productAttribute($_product, $_product->getName(), 'registroinmetro') ?></h2>
</div>
1
  • Which type of attribute you have text or dropdown? Commented Jan 2, 2019 at 13:28

3 Answers 3

0

Check below code i'm using this code. this code working fine. replace your attribute name with (Brand)

<?php
$brandname = $_product->getAttributeText('brand');
    if (trim($brandname)) {
        echo "" .$this->htmlEscape($brandname);
    }
?>
0

Try the code below:

 <div class="page-title product-title"> 
 <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>
 </div>

 <div class="codigoinmetro"> 
 <h2><?php echo $_helper->productAttribute($_product, $_product->getRegistroinmetro(), 'registroinmetro') ?></h2>
 </div>
4
  • what this $_helper point to ?
    – Sourav
    Commented Apr 17, 2018 at 10:21
  • Its points to product module (Magento core Module For Product) helper. If you open that helper file you will see "productAttribute" function. Commented Apr 17, 2018 at 10:23
  • @Sourav , $_helper in my code is the correction of the question's code. Commented Apr 17, 2018 at 10:31
  • @EmanuellVieira , had your problem solved yet? Commented Apr 19, 2018 at 9:27
0

If you have select type attribute then you can use below code to get attribute value:

$attributeName = $product->getAttributeText('attributename');
If you have input type attribute then you can use below:
$attributeName = $product->getAttributeName ();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.