Creating a mobile theme
We close the chapter with a short guide to creating a mobile theme. Elgg's view system makes it easy to create a theme for mobile devices. A mobile theme creates another viewtype that is used whenever a mobile browser is detected. In Chapter 7, we discussed how Elgg uses a default viewtype to serve web pages to a browser and an rss viewtype to serve RSS feeds to a feed aggregator. The logic and data are the same for different viewtypes, but the rendered output is different. For a mobile theme, we create a mobile viewtype and switch to this viewtype whenever a mobile browser is detected.
Plugin structure
Our mobile theme is structured like the preceding theme except that instead of putting the views in views/default/
, they are added to views/mobile/
, as follows:
In the start script, we detect mobile browsers by analyzing the user agent of the request. There are toolkits available to do this for you such as WURFL (http://wurfl.sourceforge.net/nphp/) and http://detectmobilebrowser...