0

I am trying to render an image in a Twig template like this:

<img src="{{ asset('bundles/mybundle/images/no-image.png') }}" alt="no image available" />

It is being rendered like this (with a leading slash):

<img src="/bundles/mybundle/images/no-image.png" alt="no image available" />

which causes the server to look for an image in http://myserver.com/bundles/mybundle/images/no-image.png

The problem is when I am viewing the page in dev mode, it doesn't generate the correct asset url. What it should be is:

<img src="bundles/mybundle/images/no-image.png" alt="no image available" />

which would cause the server to look in the correct location:

http://myserver.com/app_dev.php/bundles/mybundle/images/no-image.png

Is there some way around this issue? I want the images in dev mode to run through app_dev.php

5
  • 2
    Why images should run throught app_dev? Commented Jul 25, 2014 at 15:06
  • My reason is because I have different error reporting setup for dev and prod, and the images are going through prod which is triggering email errors that I don't want to receive while working in dev. Commented Jul 25, 2014 at 15:21
  • 1
    Images don't go throught any front controller, you can give a look to your /web/.htaccess file , You will notice that files are served directly Commented Jul 25, 2014 at 15:23
  • If I used assetic, they would, so when just using the asset function, they aren't? Commented Jul 25, 2014 at 15:28
  • @StevenMusumeche if you use assetic, they would only do so in Dev mode, so you don't need to dump the files every time. Use the front controller only for files that need PHP to run. Commented Jul 25, 2014 at 21:20

1 Answer 1

1

Assetic uses PHP to combine, minify and modify the assets. In development, these assets can change continue, you don't want to execute the dump command each time you changed something. That's why Assetic has a use_controller setting so assetic combines, minifies and modifies the files at request time and then returns the response as a correct CSS or JS file.

With normal assets, like images, JS files, CSS files, etc., there is nothing dynamic to run. The browser should simply request the images from the server, where they are stored. So this shouldn't go via the framework.

Sign up to request clarification or add additional context in comments.

1 Comment

So my issue is that because I am on a dev server, often the images will not exist. Since they are trying to be accessed via "prod" mode, the error reporting config for production is activated (email logs, etc), which I am trying to avoid. Is that possible without copying all of the images to my dev server (100+ GB)?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.