2

I'm using LiipImagineBundle for an application built with symfony2 and I want to display a default image, when a image does not exists. Let's say I have

<img src="{{ ('/profiles/foo.JPG') | imagine_filter('bar') }}" />

How could I display default.jpg when '/profiles/foo.JPG' does not exists?

Thanks,

mariusa
  • 53
  • 6

3 Answers3

4

This is an old question but the correct (and probably easiest) way to do this is to specify a default_image in the liip-imagine configuration file.

http://symfony.com/doc/current/bundles/LiipImagineBundle/configuration.html

retrospectacus
  • 2,518
  • 1
  • 11
  • 18
0

You test if the variable the image exist... for example is you have sent your image from a controller

just make:

{% if image is defined %}
        <img src="{{ image | imagine_filter('bar') }}" />
 {% else %}
        <img src="{{ ('/profiles/default.jpg') | imagine_filter('bar') }}" />
 {% endif %}
Delly Fofie
  • 304
  • 2
  • 9
  • Thanks, cobra18 - Thanks for your response. My scenario is this: the name of the image will be the id of the user, which always exists. Is there any possibility to display a default image in this case (if the phisically image does not exists) ? Thanks – mariusa Dec 11 '13 at 12:36
  • This is ok, indeed! Thankyou Martin Lie! – mariusa Dec 12 '13 at 15:16
0

Ok Martin Lie i have foud a link for you and i hope you will directly undeerstand the scenario because by default Twig can not test if a Phisicall object exists or not.. so you must create a service that will help you to make it directely in Twig...

Create a service for twig

Don't worry !

Community
  • 1
  • 1
Delly Fofie
  • 304
  • 2
  • 9