Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento2 Media path in .phtml file

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.

like image 459
Mitul Avatar asked Nov 29 '22 23:11

Mitul


1 Answers

This is how you get the media path from inside a block or template.

$this->getUrl('pub/media')
like image 184
1984 Avatar answered Dec 06 '22 08:12

1984