I've implemented this hack this a little differently, to make the template to use configurable.
I did try to make this a plugin, but I couldn't work out if there is a way to override the builtin template() function. Adding the config options as a plugin was doable (even for an occasional php dabbler), but seemed pointless if template.php must be modified anyway. If anyone more skilled can make this into a plugin, it would be great.
inc/template.php
// Replaces existing template() function, which must be commented out or overwritten
function template($tpl){
global $conf;
if(clientismobile() && ($conf['mobile_tpl_on'] == 1)) {
// If browser is mobile and template enabled, use it if available
if(@is_readable(DOKU_INC.'lib/tpl/'. $conf['mobile_tpl_name'] .'/'.$tpl))
return DOKU_INC.'lib/tpl/'. $conf['mobile_tpl_name'] .'/'.$tpl;
return DOKU_INC.'lib/tpl/default/'.$tpl;
} elseif (@is_readable(DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl)) {
return DOKU_INC.'lib/tpl/'.$conf['template'].'/'.$tpl;
} else {
return DOKU_INC.'lib/tpl/default/'.$tpl;
}
}
lib/plugins/config/settings/config.metadata.php
// Options in configuration page for selecting a different template for mobile browsers
// (Inserted at line 91 after normal template option)
$meta['mobile_tpl_on'] = array('onoff');
$meta['mobile_tpl_name'] = array('dirchoice','_dir' => DOKU_INC.'lib/tpl/','_pattern' => '/^[\w-]+$/');
lib/plugins/config/lang/en/lang.php
// Selectable template for mobile
$lang['mobile_tpl_on'] = 'Use different template for mobile browsers';
$lang['mobile_tpl_name'] = 'Template for mobile browsers';