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.
Community guidelines
Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.
Archive
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.
TWIG
{{ browser.platform }}
Anyway, mobile_detect has more features, and may suit you better.
To set the theme, you should simply change the config:
PHP
$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!
Log in to reply.
Suggested topics
| Topic | Participants | Replies | Views | Activity |
|---|---|---|---|---|
| 0 | 1282 | 9 years ago | ||
| 2 | 889 | 9 years ago | ||
| 2 | 4019 | 9 years ago | ||
| 1 | 2894 | 9 years ago | ||
| 3 | 1078 | 9 years ago |