bes/mobiledetect-twig-extension
最新稳定版本:v1.0.3
Composer 安装命令:
composer require bes/mobiledetect-twig-extension
包简介
MobileDetect-integration for Twig
关键字:
README 文档
README
"Mobile Detect" integration for Twig
Installation
composer require "bes/mobiledetect-twig-extension:1.*"
And register the extension:
Twig standalone
$twig->addExtension(new Bes\Twig\Extension\MobileDetectExtension());
Silex
Yay, you don't need a ServiceProvider for it!
Add the following code after registering TwigServiceProvider:
$app['twig'] = $app->share($app->extend('twig', function($twig) { /* @var $twig \Twig_Environment */ $twig->addExtension(new Bes\Twig\Extension\MobileDetectExtension); return $twig; }));
... and you are done!
Symfony3
Yay, you don't need a Bundle for it!
Add the following code to one of your services.yml, e.g.
src/<vendor>/<your>Bundle/Resources/config/services.yml or
globally in app/config/config.yml:
services: twig.mobile_detect_extension: class: Bes\Twig\Extension\MobileDetectExtension tags: - { name: twig.extension }
... and you are done!
Examples
Render different layouts:
{% extends is_mobile() ? "layout_mobile.html.twig" : "layout.html.twig" %}
Check device type:
{% if is_mobile() %} ... {% endif %} {% if is_tablet() %} ... {% endif %}
Or:
{% if is_mobile() and is_samsung() %} ... {% endif %}
You can get a list of all the known devices with:
{{ get_available_devices()|join("<br />")|raw }}
统计信息
- 总下载量: 235.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-10-03