문제

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,

도움이 되었습니까?

해결책 2

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 !

다른 팁

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

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 %}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top