Alexis_D
Alexis_D

Reputation: 1948

display an image / what does asset do?

I try to display an image which is in web/uploads/img

this image has the following name: Screenshot_2014-12-24-23-01-17.png

1/ when doing this, it works perfectly:

 <img src="{{ asset('uploads/img/Screenshot_2014-12-24-23-01-17.png') }}" />

2/ when doing the following (the path of the image is in a variable) nothing is displayed :

 <img src="{{ asset(array_image_WebPath[t]) }}" />

( with t = 1 and array_image_WebPath[1] = uploads/img/Screenshot_2014-12-24-23-01-17.png)

The fact is that I need to store my webpath of my images in an array. So what is the proper way of doing it?


EDIT: I tried with objects directly doing the following: {% for image in liste_images %} '<'img src="{{ asset(image.webpath)}}"/> {% endfor ‰} AND IT WORKS but I need to use my array to get the right image at the right place.

Upvotes: 1

Views: 916

Answers (1)

moonwave99
moonwave99

Reputation: 22817

Go with a for...in:

{% for image in array_image_WebPath %}
  <img src="{{ asset(image) }}" />
{% endfor %}

And access the loop index with either loop.index or loop.index0 [respectively 1 and 0 based].

Upvotes: 1

Related Questions