#335

Product support

Get help in the plugin support forum.

Categories

  • Developer Tools
  • Miscellaneous
  • Utility

Overview

Detects user's browser, OS, device, and so on, in PHP code and also view templates. This is a simple wrapper plugin of jenssegers/agent, and automatically installs and registers Agent facade.

Using it is as simple as this;

// in PHP
if (Agent::isAndroidOS()) {
{# in Twig template #}
{% if Agent.isAndroidOS() %}

APIs

You can use all the method available in jenssegers/agent. Here's the partial list of methods.

Magic is-method

Agent::isAndroidOS();
Agent::isNexus();
Agent::isSafari();
Agent::isiPhone();

Device Type Detection

Agent::isMobile();
Agent::isTablet();
Agent::isDesktop();
Agent::isPhone();

Robot Detection

Agent::isRobot();

Device/OS/Browser Name

Agent::device();
Agent::platform();
Agent::browser();

Match User Agent

Agent::match('regexp');

Please see jenssegers/agent for more features.

Using in view templates (pages and layouts)

Installation

From Backend

There is no special instruction. Simply search for this plugin and install.

Via Composer

Add below to the composer.json of your project.

{
    "require": [
        ...
        "pikanji/agent-plugin": "dev-master"
    ],

Execute below at the root of your project.

composer update

You can also install only pikanji/agent-plugin and its dependencies without updating other packages by specifying the package.

composer update pikanji/agent-plugin

Usage

In PHP Code

Add use Agent;, and call methods from Agent facade.

use Agent;
...

if (Agent::isFireFox()) {
...

If you don't want to use facade, you can use it like this.

use Jenssegers\Agent\Agent;
...

$agent = new Agent();
if ($agent->isFireFox()) {
...

It is just using jenssegers/agent directly. Please refer to its documentation. You don't need to install it since it is installed as the dependency of this plugin.

In Twig Templates

Agent object will be available after Agent component is added to pages or layouts. It is recommended to add the component to your layout, so that you don't have to add every page.

Preparation is to add [Agent] to the configuration section of page or layout files. There is no configuration needed for Agent component.

description = "Default layout"

[Agent]
==
<!DOCTYPE html>
...

Then you can use this Agent object to call jenssegers/agent APIs.

...
{% if Agent.isChrome() %}
...
1.0.2

Add service provider and facade automatically

Nov 28, 2017

1.0.1

First version of Agent

Nov 28, 2017