0

Where do I have to add js, css, and images in my module?

In Magento 1 I had an image stored in

/skin/frontend/base/default/black/Newsletter2Go/img/ajax-loader.gif

where do I have to put it in Magento 2 and under which path is this image accessible afterward?

1 Answer 1

1

You can add your static resources under

Vendor/Module/view/frontend/web/[js|css|images]

and you can access image in phtml file like this.

$this->getViewFileUrl('Vendor_Module::images-folder/imagename.extension');

after that do php bin/magento s:s:d -f if the image does not show up.

4
  • I tried it like this $this->getViewFileUrl('Black_Newsletter2Go::img/ajax-loader.gif');, this is the link it gave http://www.example.net/pub/static/version1568797929/frontend/Magento/luma/de_DE/Black_Newsletter2Go/img/ajax-loader.gif. I get 404 not found.
    – Black
    Commented Oct 30, 2019 at 9:39
  • DId you add ajax-loader.gif under Black/Newsletter2Go/view/frontend/web/img ?? after that do php bin/magento s:s:d -f Commented Oct 30, 2019 at 9:44
  • Yes the file is in this location. I try the command in a moment and report back.
    – Black
    Commented Oct 30, 2019 at 9:46
  • Okay if it works accept the answer so it will help to other. Commented Oct 30, 2019 at 10:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.