Symfony2 LiipImagineBundle default image

1.6k views Asked by At

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,

3

There are 3 answers

1
Delly Fofie On BEST ANSWER

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 !

2
Delly Fofie On

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 %}
0
retrospectacus On

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