thormeier / mobile-detect-light-bundle
Symfony2 扩展包,方便在 Twig 中使用 mobiledetect 类 http://mobiledetect.net/
1.0.4
2014-03-31 09:47 UTC
Requires
- php: >=5.3.3
- mobiledetect/mobiledetectlib: 2.*
- symfony/framework-bundle: 2.*
Requires (Dev)
- twig/twig: 1.15.*@dev
This package is auto-updated.
Last update: 2024-09-17 19:46:51 UTC
README
简介
这个 Symfony2 扩展包提供了三个 Twig 函数,用于检查客户端是否在使用移动或平板设备。该扩展包利用了 http://mobiledetect.net/ 提供的类。该扩展包构建得尽可能轻量,以便根据客户端的设备调整 Twig 模板。
安装
步骤 1: 使用 Composer 安装
$ php composer.phar require "thormeier/mobile-detect-light-bundle":"1.0.*"
步骤 2: 在内核中启用扩展包
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Thormeier\MobileDetectLightBundle\ThormeierMobileDetectLightBundle(),
// ...
);
}
使用方法
该扩展包提供了三个新的 Twig 函数
is_mobile()
// template.html.twig
{% if is_mobile() %}
{# do something that is only visible for mobile users, i.e. display an app store button or similar #}
{% endif %}
is_tablet()
// template.html.twig
{% if is_tablet() %}
{# do something for tablet users only #}
{% endif %}
is_desktop()
// template.html.twig
{% if is_desktop() %}
{# do something for desktop users only #}
{% endif %}