0

I want to get the current product name in static html file which is called in product view page like below file

app/design/frontend/Vendorname/themename/Aheadworks_AdvancedReviews/web/template/product/view/review/summary/container.html

0

Use this code in phtml:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentProduct = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product information
echo $currentProduct>getName();
  • No I need to get product name in static html template not in phtml file like mentioned file in my question – VDC Mar 5 at 6:50
0

Create a block

namespace Namespace\Module\Block;

class ProductDetails extends \Magento\Framework\View\Element\Template
{
    protected $registry;

    public function __construct(   
        \Magento\Framework\Registry $registry,
    )
    {       
        $this->registry = $registry;
    }

    public function getCurrentProduct() {
        return $this->registry->registry('current_product');
    }   
}

Get product information In your phtml file

$currentProduct = $block->getCurrentProduct();
echo $currentProduct->geName();

If you want to get in current product information in phtml you can use following code.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$currentProduct = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
echo $currentProduct>getName();

NOTE : Using Object Manager directly, is not a good practice

  • No I need to get product name in static html template not in phtml file like mentioned file in my question – VDC Mar 5 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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