Magento 2 get custom module image url from backend
Use \Magento\Framework\View\Asset\Repository
class
protected $_assetRepo;
public function __construct(
...
\Magento\Framework\View\Asset\Repository $assetRepo,
...
) {
...
$this->_assetRepo = $assetRepo;
...
}
Now, you can get image URL by
echo $this->_assetRepo->getUrl("Vendor_Module::images/demo.jpg");
Take a look at the Magento Marketplace module:
vendor/magento/module-marketplace/view/adminhtml/templates/index.phtml
$block->getViewFileUrl('Magento_Marketplace::partners/images/magento-connect.png');
The image is vendor/magento/module-marketplace/view/adminhtml/web/partners/images/magento-connect.png
Our image should be under web
:
view/adminhtml/web/images/demo.jpg
Try to get with the module prefix in your template:
<?php echo $block->getViewFileUrl('Your_Module::images/demo.jpg'); ?>
Remember to clear Magento Cache and may need to delete view_preprocessed
folder.
[EDIT]
In your case, you can try with
$this->getViewFileUrl('Vendor_Module::images/image-demo.jpg');