Resource icon

Browser Detection 2.3.0

No permission to download
If I don't have page caching enabled, Do I have to enable it in order to add these lines to config.php?
PHP:
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {

    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {

        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);

    });

};

I only have these memecach cache settings in my config.php
Code:
$config['cache']['enabled'] = true;
$config['cache']['provider'] = 'Memcached';
$config['cache']['config'] = [
    'server' => '127.0.0.1'
];

$config['cache']['sessions'] = true;
 
You will only need those extra lines if you have pagecaching enabled.
Something like:
Code:
$config['pageCache']['enabled'] = true;
$config['pageCache']['onSetup'] = function (\XF\PageCache $pageCache) {
    $pageCache->setCacheIdGenerator(function(\XF\Http\Request $request) {
        return \SV\BrowserDetection\CacheHelper::getPageCacheId($request);
    });
};
$config['cache']['context']['page']['provider'] = 'Redis';
$config['cache']['context']['page']['config'] = [
        'host' => '127.0.0.1',
        'port' => 6379
        ];

...but I like your question, because I have recently turned on pagecaching and totally forgot about this extra piece of code!
 
If I don't have page caching enabled, Do I have to enable it in order to add these lines to config.php?
Nope, that is only required if you are using page cache and need to cache output for mobile vs desktop clients
 
If I'm using this add-on only because it is a requirement for Elastic Search Essentials add-on and I have pagecache on.
Do I need those extra lines in config.php?
 
If you are using page cache, I'ld recommend it. Elasticsearch Essentials add-on does vary HTML based on if the user is mobile/desktop.
 
Something like this should work;
PHP:
$xf.mobileDetect && $xf.mobileDetect.isMobile()
I appreciate your help, Xon. I did try that after installing the addon - but it doesn't appear to do anything.

1644973804212.webp

I've tried with, and without both parts just in case I've misunderstood. Example -

$xf.mobileDetect && $xf.mobileDetect.isMobile()
$xf.mobileDetect
$xf.mobileDetect.isMobile()

I appreciate your time.
 
The 'isMobile' check is based on user-agent, how are you testing it?
Via dev tools on Google Chrome. I emulated an iPhone XR and a few others. I assumed as you can't edit them, they contain the appropriate user-agent strings.
 
@Xon any idea why the following conditional triggers this error?
Code:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile() || $xf.mobileDetect.is-tablet()">

  • ErrorException: Template error: [E_USER_WARNING] Cannot call method is-tablet on a non-object (NULL)
  • src/XF/Template/Templater.php:1176
 
@Xon any idea why the following conditional triggers this error?
Code:
<xf:if is="$xf.mobileDetect && $xf.mobileDetect.isMobile() || $xf.mobileDetect.is-tablet()">

The isTablet invocation isn't right, and you need brackets around the Or'ed parts.

Something like:
XML:
<xf:if is="$xf.mobileDetect && ($xf.mobileDetect.isMobile() || $xf.mobileDetect.isTablet())">
 
Top Bottom