Using MOBILE_THEME_IS_ACTIVE for custom block views
Permalink
Hello,
I am working on a mobile theme of my site using the built in theme switcher. The proper theme is being loaded based on device, however I want to use MOBILE_THEME_IS_ACTIVE with an if/else statement to create different views for blocks depending on which version of the site a user is seeing.
Within the view.php file of affected blocks, I am using
Unfortunately both mobile devices and desktops are using the mobile version of my view.php file. Please help!
I am working on a mobile theme of my site using the built in theme switcher. The proper theme is being loaded based on device, however I want to use MOBILE_THEME_IS_ACTIVE with an if/else statement to create different views for blocks depending on which version of the site a user is seeing.
Within the view.php file of affected blocks, I am using
<?php if (defined('MOBILE_THEME_IS_ACTIVE')){ //layout for mobile here } else { //layout for non-mobile here } ?>
Unfortunately both mobile devices and desktops are using the mobile version of my view.php file. Please help!
Two things that might help.
1. You can count on MOBILE_THEME_IS_ACTIVE already being set and in fact it is always defined(either true or false). By default it is false. So you can safely do this.
If you want to be super safe you can always just do
2. Be careful about Block Caching when doing mobile/desktop views. You should place
in the top of your block's controller.php BlockController class. This will prevent sites with Basic Cache enabled from only serving one or the other(first one displayed after a cleared cache) to everyone who visits your site.
Best Wishes,
Mike