I have tried lots of option in magento2 to find the media path URL
How can i find the media path URL in template.
I have try
$object_manager = Magento\Core\Model\ObjectManager::getInstance();
$dir = $object_manager->get('Magento\App\Dir');
$mediaUrl = $dir->getDir(\Magento\App\Dir::MEDIA);
But it give me error class not found. I have search and found the one solution to create function in block file but there are so many places i want to use the media path in my design
Thanks in advance.
This is how you get the media path from inside a block or template.
$this->getUrl('pub/media')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With