0

I'm working with TYPO3, and now I need difference appearance for a specific page. Example: for testAction I need a view name Test.html that's on PC So, I wonder if there is a way to change the view file when browsing by mobile?

Something like this :

if (self::isMobile()) {
    change view file = 'mobile.html'
}

Thanks in advance.

Daniel
  • 6,412
  • 2
  • 29
  • 43
Diego
  • 11
  • 2

1 Answers1

0

Sorry but this is not possible as the server doesn't know anything about the client's capabilities like if it is a phone or the screen size!

Best would be to check this via JavaScript, e.g using https://modernizr.com/ or check out e.g. What is the best way to detect a mobile device in jQuery?. In the template you would render both types and depending on the JS check show/hide the content.

Georg Ringer
  • 6,471
  • 1
  • 13
  • 33
  • Thanks for your reply. I think you are wrong. With simple php code like this, we can know which device you're using function isMobile() { return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]); } if (isMobile()) { die('Mobile'); } else { die('pc'); } – Diego Aug 10 '17 at 03:15
  • It's possible but not reliable and bad practice. But if you want to go that way, just call your method (or use one of those php browser sniffer libraries you'll find on github) and set a view variable like `$this->view->assign('isMobile', true);` and use that in your template to output something different (e.g. a different partial or a simple if will do). – Wolfgang Aug 10 '17 at 06:33
  • I would not recommend to rely on the user agent – Georg Ringer Aug 10 '17 at 08:30