1

I'm using Vich uploader. Everything is fine, I can see the pic I have uploaded. But when there's none, there is a blank, which is kind of ugly. So I decided to upload an icon instead.

I'm trying to do something like: if you don't upload a picture, there will be a default one.

So in my show.index view, I have tried many combinations like:

<div class="col-6">
    <div class="d-flex justify-content-center align-items-center">
        {% if lieu.imageFile == false %}
        <img style="max-width: 100%" src= "{{ vich_uploader_asset(lieu, 'imageFile')}}" >
        {% else %}
        <img src="{{asset('defaultImage/defaultImage.jpg')}}" alt="">
        {% endif %}
    </div>
</div>

lieu is my Entity name. ImageFile is the name of the image uploaded.

When I change the if statement to TRUE, it will work, I can see the "defaultImage" I just set up. But then when I go on an other view with no image uploaded, it will show a blank div. Again if I change back to false, it will work. It's like the if statement is only working manually.

I've tried to change the location of the defaultimage I thought it was on conflict with the repository of the vich uploader repository.

I've tried to write, if and if else but it doesn't work neither.

Sorry for my English. Many thanks for your help.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
  • how about `{% if lieu.imageFileName == false %}`? – craigh Jan 20 '23 at 00:37
  • Did you enable twig's debug mode? Are you sure `imageFile` is a public accessible property or that you have a public getter named `getImageFile`? Did you try to `{{ dump(lieu.imageFile) }}`? – DarkBee Jan 20 '23 at 05:49
  • i'm very sorry guys, i haven't had any notifications on my email and i'm not used to check here. i've just tried lieu.imageName and it works!!! Thanks a lot! (for the dump, i still don't understand how it works, i will watch some tutos thanks for the help) – Gerry Gerry Feb 10 '23 at 12:49

0 Answers0