-
Notifications
You must be signed in to change notification settings - Fork 1
Browser Service
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.
$template['browser']->ip()$template['browser']->is_desktop()$template['browser']->is_mobile()$template['browser']->is_tablet()$template['browser']->name()$template['browser']->platform()$template['browser']->version()
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 %}
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() }}
- If you spot a typo or want to contribute an article, a how-to or a tip, feel free to edit the Wiki directly
- If you you have any questions, please visit the phpManufaktur Support Forum
This Documentation is part of the kitFramework Project
© 2014 by phpManufaktur, kitFramework and TemplateTools are published under MIT license.