Resource icon

Free XF2 Add-ons [Xon] Browser Detection 2.2.0
A light-weight shim around Mobile detect for XenForo 2

Compatible XF versions
2.1, 2.2
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.

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


HTML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Firefox')">
Is Firefox
<xf:else />
Not Firefox
</xf:if>


HTML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Chrome')">
Is Chrome
<xf:else />
Not Chrome
</xf:if>

Usage (in php)


PHP:
$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;

PHP:
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
$pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
});
};
  • Like
Reactions:CODE
Author
FateKid
Downloads
1
Total Views
222
Released
Version
2.2.0
Rating
0.00 star(s) 0 ratings

More files from FateKid

Share this resource

Similar resources

Alert Improvements by Xon FateKid
A collection of improvements to the XenForo Alerts system.
0.00 star(s) 0 ratings
Downloads
3
Attachment Improvements By Xon FateKid
A collection of improvements to XF's attachment system
0.00 star(s) 0 ratings
Downloads
0
Adds the in-line moderator option "Change Post Date".
0.00 star(s) 0 ratings
Downloads
0