TYPO3 Mobile browser switch

From snippet wiki
Jump to navigation Jump to search

Within localconf.php define a short user funtion:

function user_mobileswitch() {
        $browser = get_browser(null, true);
 
        if($browser['ismobiledevice']) {
                return true;
        } else {
                return false;
        } // if
} // function

And in your typoscript template setup near the end you react on that function:

# Redirect if browscap.ini detects mobile (see localconf.php)
[userFunc = user_mobileswitch()]
config >
config.additionalHeaders = Location: http://m.example.com
page >
page = PAGE
page.10 = TEXT
[global]

Just be sure to enable browscap in your php.ini and point to a current version of that file.

One extension to this can be disabling the switch for tablet devices. In that case change the if line from above to this:

        if($browser['ismobiledevice'] && !$browser['istablet']) {

You might want to override the switch by setting some url parameters and remembering that in a session cookie.