Skip to main content
1 of 2

Magento2 getViewFileUrl on backend and frontend

I have a file called image.png

Folder structure:

-app
   -code
       -Roland
           -HelloWorld
               -view
                   -adminhtml
                       -web
                   -frontend
                       -web
                          -image.png

When I call this on frontend:

$this->getViewFileUrl("Roland_HelloWorld::image.png");

Result: http://localhost/magento2/pub/static/frontend/Magento/luma/en_US/Roland_HelloWorld/image.png

And the image loads fine.


When I call this on backend:

$this->getViewFileUrl("Roland_HelloWorld::image.png");

Result: http://localhost/magento2/pub/static/adminhtml/Magento/backend/en_US/Roland_HelloWorld/image.png

The image is not loading as it is not in the adminhtml/web/ folder.

Is there any way to load the static url for this asset with the frontend application area? What would be the official way, I do not want to duplicate this image into both folder?