i need to show an attribute to product page under the name of the product. The attribute is text and the code is plustile

I try to load it to a shopbybrand extension that has a block in the wanted area with the code

// check attribute exists (Where 'dimension' is the attribute code for your attribute)
if ($attribute = $this->getProduct()->getResource()->getAttribute('flooring_width')): ?>
    // get label for the current store (in case you have multiple stores and languages)
    $_attribute_label = $attribute->getStoreLabel(Mage::app()->getStore()->getName());
    // get the attribute value (for other attributes change getDimension to getName where name is the name of your attribute );
    $_attribute_value = $this->getProduct()->getFlooringWidth();
    // check there is a value for the attribute
    if (isset($_attribute_value)): ?>
            <?php echo $_attribute_label . ': ' . $_attribute_value; ?>
    <?php endif; ?>
<?php endif; ?>


$_product = $block->getProduct();
$attrData = $_product->getData('plustitle');
$blockTitle = $this->getData('title');
if (trim($attrData) !== "") : ?>
    <div class="product-full-width-section">
        <h2 class="product-section-title"><?= $blockTitle; ?></h2>
        <?php echo $attrData; ?>
        <?php echo 'mplampla';?>
<?php endif; ?>

i get Error: Call to a member function getResource() on null in

i try to make an extension like https://www.dckap.com/blog/display-custom-attribute-value-product-viewlist-page-magento-2/

but with no success

Can you advise for the correct way to do it or Do you know any extension to do this?

Thank you

3 Answers 3


first added this code on your phtml and then use the product object :

$_helper = $this->helper(Magento\Catalog\Helper\Output::class);
$_product = $block->getProduct();

if (!$_product instanceof \Magento\Catalog\Model\Product) {
  • It don't run anything after ``` if (!$_product instanceof \Magento\Catalog\Model\Product) { return; } ```
    – Pantelis
    Jan 15, 2021 at 10:07
  • my full code i try to run is ``` <?php $_helper = $this->helper(Magento\Catalog\Helper\Output::class); $_product = $block->getProduct(); if (!$_product instanceof \Magento\Catalog\Model\Product) { return; } $attrData = $_product->getData('plustitle'); $blockTitle = $this->getData('title'); if (trim($attrData) !== "") : ?> <div class="product-full-width-section"> <h2 class="product-section-title"><?= $blockTitle; ?></h2> <?php echo $attrData; ?> <?php echo 'mplampla';?> </div> <?php endif; ?> ```
    – Pantelis
    Jan 15, 2021 at 10:09

Try to get product data from your block i.e. $block->getProduct


I solve it with replacing the

$_product = $block->getProduct();


$_product = \Magento\Framework\App\ObjectManager::getInstance()

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.