symfonyliipimaginebundle

Liipimaginebundle - images in FOR loop


I've got a problem with showing thumbnails using Liipimaginebundle in TWIG template.

I'm rendering an index:

return $this->render('ad/index.html.twig', array(
        'ads' => $ads,
    ));

and in index.html.twig I'm using FOR loop to show thumbnails related to ads.

{% for ad in ads %}
   //with parameter - doesn't work
   {% set img = ad.mainPhoto %}   
   <img src="{{ img | imagine_filter('thumb') }}" />  

   //working fine
   <img src="{{ asset('/uploads/2.png') | imagine_filter('thumb') }}" />
{% endfor %}

mainPhoto stores a path to photo related to current ad - for example:

/uploads/2.png

While using an "img" parameter, I've got an exception:

An exception has been thrown during the rendering of a template ("Parameter "path" for route "liip_imagine_filter" must match ".+" ("" given) to generate a corresponding URL.").

What is the correct way to define the path in this case?


Solution

  • You are passing only the path as a string to the imagine_filter, add the asset and it should work:

    {% for ad in ads %}
       {% set img = ad.mainPhoto|default %}
       {% if img <> "" %}
           <img src="{{ asset(img) | imagine_filter('thumb') }}" />  
       {% endif %}
    {% endfor %}