0

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?

mmateja
  • 3
  • 3

1 Answers1

3

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 %}
Veve
  • 6,643
  • 5
  • 39
  • 58
  • Thanks for help! It was my bad... Unfortunately I had one "ad" without "mainPhoto"... that was the reason of exception. BTW img | imagine_filter('thumb') works too :) – mmateja Mar 02 '17 at 18:52
  • It works... until you have different asset environments. (Think CDN, server for static files, ...). I've added a verification for mainPhoto based on the first part of your comment. – Veve Mar 03 '17 at 09:59