Domanda

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,

È stato utile?

Soluzione 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 !

Altri suggerimenti

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 %}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top