Comment 5 for bug 1271779

Revision history for this message
Aaron Wells (u-aaronw) wrote :

Hi Corey,

There's a flag you can use within a .tpl template to see whether the current user is on a mobile device or not. Two flags, actually.

- $HANDHELD_DEVICE will be true if the user is on a tablet or phone.
- $MOBILE will be true if the user is on a phone.

You can use these in a template file like so:

 {if $HANDHELD_DEVICE}<div>mobile content!</div>{else}<div>desktop content!</div>{/if}

We detect mobile devices using the MobileDetect library (http://mobiledetect.net/ ). It's worth noting that there's a site configuration option to let users disable device detection, in which case if a user disables it, $HANDHELD_DEVICE and $MOBILE will always be false.

We can also detect whether the user is, specifically, on a tablet device, but we're not currently passing that info through to the templates. Though if that's necessary, we could do so pretty easily.

... on the other hand, your specific question was about whether you can change the template file that gets displayed, based on the device detection. And the answer to that, is no, you can't. The specific template file Mahara shows, will always be the one from the user's theme (or, if their theme doesn't provide a copy of that template, it'll show the inherited template from the theme's parent, all the way up to the "raw" theme which is the root parent of all themes.)

Cheers,
Aaron