1

i'm trying to display some pictures on my "website" In order to do so, i'm using Vitch. I did the upload without issues, images are updating into the right folder, but nothing is display when i'm trying to get imgs from my view.

There is my Yaml config file

vich_uploader:
db_driver: orm
mappings:
    property_image:
        uri_prefix: /images/properties
        upload_destination: '%kernel.project_dir%/public/images/properties'
        namer: Vich\UploaderBundle\Naming\UniqidNamer

And there is my view

<div class="card mb-4">
<div class="card-body">
{% if property.filename %}
    <img src="/images/properties/{{ property.filename }}">
{% endif %}
    <h5 class="card-title">
        <a href="{{ path('property.show', {slug: property.slug, id: property.id}) }}">
            {{ property.title }}
        </a>
    </h5>
    <p class="card-text">{{ property.surface }} m³ - {{ property.city }} ({{ property.postalCode }})</p>
    <div class="text-primary" style="font-size:2rem; font-weigth:bold;">
       {{ property.FormatedPrice }} €
    </div>
</div>

Thanks for your help

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130
Séverine F
  • 73
  • 1
  • 7

1 Answers1

0

As you're using a custom naming-strategy ... your images aren't displayed because their paths are incorrect.

VichUploaderBundle provides a twig method to correctly resolve the path to the images.

Example usage:

{# 
  the second parameter is the name of the property 
  with the @UploadableField annotation
#}
<img src="{{ vich_uploader_asset(item, 'imageFile') }}">
Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130