Skip to content
hertsch edited this page May 9, 2014 · 3 revisions

The Browser Service supports you with some usefull functions to detect the used Browser, Version, Platform and used Device, i.e. if the Browser is executed on a mobile device or at a Desktop. These functions can be used at a php script but also within a twig template.

###ip(), browser_ip()

This function will return the IP address which is used by the browser.

Usage php

<p>You are using the IP address <?php $template['browser']->ip(); ?></p>

Usage twig (as Function)

<p>You are using the IP address {{ browser_ip() }}</p>

###is_desktop(), browser_is_desktop()

This function will return true if the used device is a Desktop.

Usage php

<?php 
    if ($template['browser']->is_desktop()) {
        // do anything a Desktop Devices
        echo 'You are using a Desktop!';
    } 
?>

Usage twig (as Function)

{% if browser_is_desktop() %}
    {# do anything at Desktop Devices #}
    {{ 'You are using a Desktop!'|trans }}
{% endif %}

###is_mobile(), browser_is_mobile()

This function will return true if the used device is a Mobile Device.

Usage php

<?php 
    if ($template['browser']->is_mobile()) {
        // do anything a Mobile Devices
        echo 'You are using a Mobile Device!';
    } 
?>

Usage twig (as Function)

{% if browser_is_mobile() %}
    {# do anything at Mobile Devices #}
    {{ 'You are using a Mobile Device!'|trans }}
{% endif %}

###is_tablet(), browser_is_tablet()

This function will return true if the used device is a Tablet.

Usage php

<?php 
    if ($template['browser']->is_tablet()) {
        // do anything a Tablet Devices
        echo 'You are using a Tablet!';
    } 
?>

Usage twig (as Function)

{% if browser_is_tablet() %}
    {# do anything at Tablet Devices #}
    {{ 'You are using a Tablet!'|trans }}
{% endif %}

###name(), browser_name()

This function will return the name of the current browser

Usage php

<?php echo $template['browser']->name(); ?>

Usage twig (as Function)

{{ browser_name() }}

You can use the Browser Constants for comparisons.

###platform(), browser_platform()

This function will return the platform where the current Browser is executed.

Usage php

<?php echo $template['browser']->platform(); ?>

Usage twig (as Function)

{{ browser_platform() }}

You can use the Browser Constants for comparisons.

###version(), browser_version()

This function will return the version of the current Browser.

Usage php

<?php echo $template['browser']->version(); ?>

Usage twig (as Function)

{{ browser_version() }}

Clone this wiki locally