Is there a specific way to make my images appear in the pub static folder?

I have my image uploaded in the web/images/ directory and when I try and call them in my phtml file I am getting a broken image link.

I manually checked the pub/static/TestTheme/images directory and none of my images were being added. This is what I am using in my phtml file.

    <img src=”<?php echo $this->getViewFileUrl('images/test.png'); ?>” alt="test">

Switch to the developer mode, and the static content will be deployed automatically. Uncomment below line inside .htaccess of root folder

SetEnv MAGE_MODE developer

if still issue ,use

command to deploy static files

php -f magento setup:static-content:deploy

note: right click /bin then select 'Open command window here', before using command, you must have already installed composer in your system.

The developer mode is intended to be used and useful during development. Particularly, Magento in developer mode shows exceptons on screen instead of showing a generic error message like "There has been an error processing your request".

| improve this answer | |

Your code is correct. Just make sure the followings when you make changes :

  • Remove all files under var/view_preprocessed/
  • Remove all files under pub/static/
  • Flush Magento Cache magento cache:flush

Magento will automatically copy your image to pub/static folder when you reload your page containing the image you want.

Ref: http://devdocs.magento.com/guides/v2.0/architecture/view/static-process.html#static-view-files-url-resolution

| improve this answer | |

You need to run the below command.

bin/magento setup:static-content:deploy 
| improve this answer | |

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.