我目前正在使用twig作为我的模板引擎,我想在使用移动和桌面加载网站时加载不同的图像URL.是否有捷径可寻?
所以我想做这样的事情:@H_403_3@
- {% if (mobile) %}
- <img src="{{ picture.getLowresimageurl() }}"/>
- {% else %}
- <img src="{{ picture.getMedresimageurl() }}"/>
- {% endif %}
有没有办法做到这一点?@H_403_3@
解决方法
您可以使用
MobileDetectBundle检测移动设备,管理移动视图并重定向到移动设备和平板电脑版本
Twig Helper@H_403_3@
- {% if is_mobile() %}
- {% if is_tablet() %}
- {% if is_device('iphone') %} # magic methods is[...]
Twig的例子@H_403_3@
- {% if is_mobile_view() %}
- {% extends "MyBundle:Layout:mobile.html.twig" %}
- {% else if is_tablet_view() %}
- {% extends "MyBundle:Layout:tablet.html.twig" %}
- {% else if is_full_view() or is_not_mobile_view() %}
- {% extends "MyBundle:Layout:full.html.twig" %}
- {% endif %}