Symfony 5.4.x-7.0 bundle to detect mobile devices, manage mobile view and redirect to the mobile and tablet version.
This bundle is a fork of suncat2000/MobileDetectBundle. As this project doesn't look maintained anymore, we decided to create & maintain a fork. For more information read our manifest.
This Bundle use MobileDetect class and provides the following features:
-
Detect the various mobile devices by Name, OS, browser User-Agent
-
Manages site views for the various mobile devices (
mobile
,tablet
,desktop
) -
Redirects to mobile and tablet sites
composer require tattali/mobile-detect-bundle
Install with Symfony legacy versions: here
use Detection\MobileDetect;
public function someaction(MobileDetect $mobileDetector)
{
$mobileDetector->isMobile();
$mobileDetector->isTablet();
$mobileDetector->is('iPhone');
}
With Twig
{% if is_mobile() %}
{% if is_tablet() %}
{% if is_device('iPhone') %} # magic methods is[...]
Available User-Agents (uaMatch) with the php is()
and twig is_device()
here
For switch device view, use device_view
GET parameter:
https://localhost:8000?device_view={desktop/mobile/tablet}
Any feedback and contribution will be very appreciated.
This bundle is under the MIT license. See the complete license in the bundle
Original authors: suncat2000, HenriVesala, netmikey and all contributors