1

In my controller I have the following code but I want to display also the meta title of the product in the browser. Can anyone help me with this? Thanks!

class Product extends \Magento\Framework\App\Action\Action
{
protected $pageFactory;
public function __construct(Context $context, PageFactory $pageFactory)
{
    $this->pageFactory = $pageFactory;
    return parent::__construct($context);
}

public function execute()
{
    $page_object = $this->pageFactory->create();
    return $page_object;
}
}

1 Answer 1

0

Try following way

/** @var \Magento\Framework\View\Result\Page $resultPage */
$resultPage = $this->resultPageFactory->create();
// set title
$resultPage->getConfig()->getTitle()->set('Something');

// get title
echo $resultPage->getConfig()->getTitle()->get();

// get meta information
print_r($resultPage->getConfig()->getMetadata());

Check available method into following class

Magento/Framework/View/Page/Config.php
3
  • Thanks for the reply but I need the meta title to be displayed not the page title. any idea?
    – Th. Schott
    Commented Aug 27, 2016 at 15:36
  • check updated answer
    – Sohel Rana
    Commented Aug 27, 2016 at 15:41
  • Unfortunately I cant figure it :-(
    – Th. Schott
    Commented Aug 27, 2016 at 16:04

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.