我在 TWIG 模板中使用 Liipimaginebundle 显示缩略图时遇到问题。
我正在渲染一个索引:
return $this->render('ad/index.html.twig', array(
'ads' => $ads,
));
在 index.html.twig 中,我使用 FOR 循环来显示与广告相关的缩略图。
{% 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 存储与当前广告相关的照片路径 - 例如:
/uploads/2.png
在使用“img”参数时,我遇到了一个例外:
在渲染模板期间抛出异常(“路由“liip_imagine_filter”的参数“path”必须匹配“.+”(“”给定)以生成相应的URL。”)。
在这种情况下定义路径的正确方法是什么?