How to get image url of web/images folder in custom module.

How to get image url of web/images folder    in custom module.

For image url inject \Magento\Framework\View\Asset\Repository in constructor

code:

protected $_assetRepo;

public function __construct(\Magento\Framework\View\Asset\Repository $assetRep)

{

$this->_assetRepo = $assetRepo;

}

Now, get image URL using

$mediaUrl = $this->_assetRepo->getUrl("Vendor_Module::images/info.png");



Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.