I´m having problems using VichUploaderBundle. Uploads files correctly, but when I write
<td><img src="<img src="{{ vich_uploader_asset(entity, 'image') }}" alt="{{ entity.nombre }}" />"</td>
to display an uploaded picture, I have this error:
An exception has been thrown during the rendering of a template ("Unable to get filename property value: "image"") in SuperlineaBundle:Instruccion:index.html.twig at line 21.
I tried to get helper on the controller and it works:
$helper = $this->container->get('vich_uploader.templating.helper.uploader_helper');
$path = $helper->asset($entities[0], 'image');
ladybug_dump( $path );
Displays: string(25) “/images/uploads/video.png”
Any help or clue?
This is my entity: http://pastebin.com/d8X72zK4
This is my config:
vich_uploader:
db_driver: orm
twig: true
gaufrette: false # set to true to enable gaufrette support
storage: vich_uploader.storage.file_system
mappings:
uploads:
uri_prefix: /images/uploads
upload_destination: %kernel.root_dir%/../web/images/uploads
namer: ~ # specify a file namer service id for this entity, null default
directory_namer: ~ # specify a directory namer service id for this entity, null default
delete_on_remove: true # determines whether to delete file upon removal of entity
inject_on_load: true # determines whether to inject a File instance upon load
pdfs:
uri_prefix: /images/pdf
upload_destination: %kernel.root_dir%/../web/images/pdf
namer: ~ # specify a file namer service id for this entity, null default
directory_namer: ~ # specify a directory namer service id for this entity, null default
delete_on_remove: true # determines whether to delete file upon removal of entity
inject_on_load: true # determines whether to inject a File instance upon load
And this is my twig template:
…
{% for entity in entities %}
<tr>
<td><a href="{{ path('instruccion_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.nombre }}</td>
<td>{{ entity.foto }}<img src="<img src="{{ vich_uploader_asset(entity, 'image') } }" alt="{{ entity.nombre }}" />"</td>
<td>{{ entity.video }}</td>
<td>
<ul>
<li>
<a href="{{ path('instruccion_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('instruccion_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
correct this line
you have double img tag