Liipimaginebundle - FOR 循环中的图像
Liipimaginebundle - images in FOR loop
我在使用 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" 参数时,出现异常:
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.").
在这种情况下定义路径的正确方法是什么?
您仅将路径作为字符串传递给 imagine_filter
,添加 asset
,它应该可以工作:
{% for ad in ads %}
{% set img = ad.mainPhoto|default %}
{% if img <> "" %}
<img src="{{ asset(img) | imagine_filter('thumb') }}" />
{% endif %}
{% endfor %}
我在使用 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" 参数时,出现异常:
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.").
在这种情况下定义路径的正确方法是什么?
您仅将路径作为字符串传递给 imagine_filter
,添加 asset
,它应该可以工作:
{% for ad in ads %}
{% set img = ad.mainPhoto|default %}
{% if img <> "" %}
<img src="{{ asset(img) | imagine_filter('thumb') }}" />
{% endif %}
{% endfor %}