I am trying to get the current pages meta data in title.phtml
on Magento 2 so that I can have a sub title and slight description on the page.
But I cant find anything for how to retrieve this information, only how to set it.
I have tried things like:
$this->pageConfig->getTitle();
and
$this->getLayout()->getBlock('head')->getTitle();
and
$resultPage->getConfig()->getTitle()
But all without success. I know this is all quite new at the moment but can anyone tell me how to do this?
Best Answer
A way to get the meta data could be:
However this does not take into account the default settings under Content > Design > Configuration > HTML Head
This only works for cms pages, i guess.
Finally i used this in my case:
Have look in the
Magento\Framework\View\Page\Config
i think there is literally agetMetadata
method.