After a few bits and bats I have managed to get it working.
After the composer install just adding this to app/controllers/App.php
<?php
namespace App\Controllers;
use hisorange\BrowserDetect\Parser as Browser;
use Sober\Controller\Controller;
class App extends Controller
{
public function browser()
{
return new Browser;
}
// other stuff...
}
This then allows me to call the libraries functions in my blade templates like so…
@if($browser::isDesktop())
<p>This is a desktop</p>
@endif
Yeah I totally get that client-side browser detection is a solid way to go about this in general but what I was more interested in was with how library detects devices:
@mobile
<p>This is the MOBILE template!</p>
@include('your-mobile-template')
@endmobile
@tablet
<p>This is the TABLET template!</p>
<link rel="stylesheet" href="tablet.css" title="Reduce the page size, load what the user need">
@endtablet
@desktop
<p>This is the DESKTOP template!</p>
@enddesktop
The blade stuff is only useable in a full Laravel framework but for me and other developers I know this could cut down on quite a lot the output of HTML, CSS and JS when building fully responsive websites. My thought being that server-side detection would be faster and wouldn’t need JS or CSS to be loaded before detection occurs?
Admittedly I’m only testing out this library for fun at the moment but if it proves to be of real use in a production environment, I was just curious as to its potential in Sages core.