Hello,
I’m trying to develop a plugin which change theme if mobile is detect.
I found how to get the current theme in the array with grav['config']->get('system.pages.theme')
and how to find all theme grav['themes']->all()
But I don’t know how to set/change the current theme to another one.
For your information, my plugin is using Mobile_Detect.php for mobile detection.
Thanks.
A couple of things. Grav already includes https://github.com/donatj/PhpUserAgent and is available to use in your plugins. It has a simple platform detection function. It doesn’t actually have a simple way to tell you if you are on a mobile platform or not, although it detects a variety of mobile platforms.
{{ browser.platform }}
Anyway, mobile_detect
has more features, and may suit you better.
To set the theme, you should simply change the config:
$grav['config']->set('system.pages.theme', 'mobile_theme')
You should do this before the theme is rendered. So pick an appropriate event:
Thanks! Its works!
nice!