superbig / craft3-mobiledetect
Use Mobile_Detect for detecting mobile devices (including tablets)
Installs: 49 418
Dependents: 0
Suggesters: 0
Security: 0
Stars: 19
Watchers: 2
Forks: 2
Open Issues: 2
Type:craft-plugin
Requires
- craftcms/cms: ^4.0.0
- mobiledetect/mobiledetectlib: ^2.8
README
Use Mobile_Detect for detecting mobile devices (including tablets)
Requirements
This plugin requires Craft CMS 3.0.0-beta.23 or later.
Installation
To install the plugin, follow these instructions.
-
Open your terminal and go to your Craft project:
cd /path/to/project
-
Then tell Composer to load the plugin:
composer require superbig/craft3-mobiledetect
-
In the Control Panel, go to Settings → Plugins and click the “Install” button for MobileDetect.
MobileDetect Overview
fairly complete wrapper for the Mobile_Detect library by @serbanghita.**
Using MobileDetect
The plugin exposes most of Mobile_Detect's methods, and can be used in your Twig:
{{ craft.mobileDetect.isMobile ? 'I am mobile.' : 'I am not mobile.' }}
...or as a PHP service:
<?php $isMobile = MobileDetect::$plugin->mobileDetect->isMobile();
Methods/usage
Device detection
isMobile
Detects all mobile devices, both phones and tablets
isTablet isPhone
Mobile OS detection
isiOS isAndroidOS isBlackBerryOS isPalmOS isSymbianOS isWindowsMobileOS isWindowsPhoneOS
Other methods
is(key)
Test for anything, e.g. is('iphone')
match(pattern)
Test using regular expressions
version(component)
Get the version of a component, e.g. version('iPhone')
mobileGrade
Get browser grade (e.g. "A")
getScriptVersion
Prints the MobileDetect library's version
getUserAgent setUserAgent(userAgent) getMobileHeaders getHttpHeaders setHttpHeaders(httpHeaders) getCfHeaders setCfHeaders(cfHeaders)
Brought to you by Superbig