- XF兼容
- 2.1.x
- 2.2.x
用法的轻量级垫片Mobile_detect(在模板中)
该插件注入全局变量,在调用任何方法之前检查是否设置了该变量,以防止在升级期间出现错误或是否禁用了该插件.
[CODE lang="php" title="PHP用法"]$mobileDetect = \SV\BrowserDetection\Listener::getMobileDetection();
$isMobile = $mobileDetect && $mobileDetect->isMobile() ? "_m1" : "_m0";[/CODE]
与XF2.1+整页缓存集成移动检测,添加到config.php这个;
[CODE lang="php" title="XF2.1页面缓存"]$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
$pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
});
};[/CODE]
该插件注入全局变量,在调用任何方法之前检查是否设置了该变量,以防止在升级期间出现错误或是否禁用了该插件.
$xf.mobileDetect
CSS:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile()">
Is Mobile
<xf:else />
Not Mobile
</xf:if>
XML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Firefox')">
Is Firefox
<xf:else />
Not Firefox
</xf:if>
XML:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.is('Chrome')">
Is Chrome
<xf:else />
Not Chrome
</xf:if>
$isMobile = $mobileDetect && $mobileDetect->isMobile() ? "_m1" : "_m0";[/CODE]
与XF2.1+整页缓存集成移动检测,添加到config.php这个;
[CODE lang="php" title="XF2.1页面缓存"]$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
$pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
});
};[/CODE]