leowebguy/device-detect

Craft plugin for detecting devices, OS, bots and more

Installs: 3 277

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 1

Type:craft-plugin

3.0.0 2024-03-27 01:54 UTC

This package is auto-updated.

Last update: 2024-04-27 04:03:16 UTC


README

Detect devices, OS, bots and more

Wrapper around MobileDetect by @serbanghita

Installation

Open your terminal and go to your Craft project:

composer require leowebguy/device-detect -w && php craft plugin/install device-detect

Usage

The plugin exposes most of MobileDetect's methods, and can be used in your Twig:

{{ craft.deviceDetect.isMobile ? 'I am mobile.' : 'I am not mobile.' }}

Devices

{{ craft.deviceDetect.isMobile }}
{{ craft.deviceDetect.isTablet }}
{{ craft.deviceDetect.isiPad }}
{{ craft.deviceDetect.isPhone }}

OS

{{ craft.deviceDetect.isiOS }}
{{ craft.deviceDetect.isiPadOS }}
{{ craft.deviceDetect.isAndroidOS }}

Bots

{{ craft.deviceDetect.isBot }}
{{ craft.deviceDetect.isMobileBot }}

User agent

{{ craft.deviceDetect.getUserAgent }}

getUserAgent returns string i.e. Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36