Resource icon

xF2 Add-on Browser Detection 2.2.0

No permission to download
Compatible XF Versions
2.1, 2.2
Visible Branding
No
Additional Requirements
php 7.0+
A light-weight shim around Mobile_detect for XenForo 2

Usage (in templates)

The add-on injects the global variable $xf.mobileDetect, check that the variable is set before calling any methods to prevent errors during upgrades or if the add-on is disabled.

Code:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile()">
Is Mobile
<xf:else />

Not Mobile
Code:
</xf:if>
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Firefox')">
Is Firefox
<xf:else />
Not Firefox
Code:
</xf:if>
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Chrome')">
Is Chrome
<xf:else />
Not Chrome
</xf:if>
Usage (in php)

Code:
$mobileDetect = \SV\BrowserDetection\Listener::getMobileDetection();
$isMobile = $mobileDetect && $mobileDetect->isMobile() ? "_m1" : "_m0";
XF2.1 Page caching

The integration mobile detection with XF2.1+ full-page caching, add to the config.php this;
Code:
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};
Contributing features or bug fixes
Please create a Github Pull request via the "More information." link.
Author
DareDevil
Downloads
57
Views
920
Last update
Rating
0.00 star(s) 0 ratings

More resources from DareDevil

Latest updates

  1. 2.2.0 - Feature/Maintenance update

    Implement caching wrapper around Mobile_detect::match calls. Forward unknown function calls to...
  2. 2.1.3 - Compatibility update

    3rd party add-on compatibility fix, rework how html element css injection works
  3. 2.1.0 - Feature update

    Require php 7.0+ Require XenForo 2.1+ Inject is-mobile or is-tablet into PAGE_CONTAINER html...
Top