I've added some images to my module eg.


Having run bin/magento setup:static-content:deploy I now see these have been published to the pub directory


I can access these from the web


My question

What is the proper way to refer to these files in a .phtml file in my module?

It seems like putting the path from /static forward would be pretty hacky. My guess is there's some way to refer to the module and start off with /images or similar and provide a relative path to the files, but I'm not sure where to look for the answer.


Wow, a few minutes later and I've found the answer. I'll leave this up as a Q/A style post as I think it could be helpful for other folks.


FWIW I started off reading this article from Alan Storm; it just didn't have the bit about how to refer to static assets like image files from templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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