Auto Template Switcher for iPhone
Written by kksou   
Monday, 01 September 2008

This module allows you to automatically switch to a different template just for iPhone or iPod users.

For all other users using standard browsers (e.g. Mozilla, IE, Safari), they will see your default template.

I designed this initially to serve different templates for iPhone/iPod users. But you can use this for other browsers too, for example, if you wish to serve different templates for iMac, Windows and Linux users.


Important for Joomla 1.5 users !!!

You need to change one line in the Joomla core for this to work.

In file /includes/application.php in function getTemplate (around line 281), change the line

if ($template = $this->get('setTemplate')) {

to this one

if ($template = $this->getUserState('setTemplate')) {


Latest Version

v1.01 (for Joomla 1.0) and v1.51 (for Joomla 1.5)
Released September 23, 2008

In addition to switching template on different user agents, you can now also specify the inital designated page that will be displayed when a template-switch occurs. For example, you can automatically redirect an iPhone user to a dedicated iPhone home page when he or she comes to your site.

You can specify different url page corresponding to each template and user agent in the parameters page of the Module Manager.

Note that a redirect to the designated page will only occur when there's a template switch. If there's no swtich of template, there will be no redirect to the page.

Thanks to Wayne Geddings for suggesting the above enhancement.

How it works?

The module uses

$_SERVER['HTTP_USER_AGENT']
to detect user's browser. For example, the value returned by iPhone is:

Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_0 like Mac OS X; en-us) 
AppleWebKit/525.18.1(KHTML, like Gecko) Version/3.1.1 Mobile/5A345 Safari/525.20

The program uses preg_match(), so you only need to use a string in $_SERVER['HTTP_USER_AGENT'] that uniquely identifies the browser you want to identify.

The module allows you to specify up to 3 different browser user agents. For example, when you first installed the "Auto Template Switcher" module, the default settings are as follows:

Browser 1: iPhone
Browser 2: MSIE
Browser 3: Mozilla

For each browser, you specify the corresponding templates. The following shows the default settings when the module is first installed. The templates are those that come bundled with standard Joomla installation.

BrowserJoomla 1.0Joomla 1.5
browser1 = iPhonetemplate1 = madeyourwebtemplate1 = beez
browser2 = MSIEtemplate2 = madeyourwebtemplate1 = beez
browser3 = Mozillatemplate3 = rhuk_solarflare_iitemplate1 = rhuk_milkyway
default browsertemplate = rhuk_solarflare_iitemplate = rhuk_milkyway

The default browser is used when there's no match against browser 1, browser 2 or browser 3.

Note that the auto-switching of the template is achieved through the use of module. The only purpose of the module is to detect the user agent and auto switch the template. It does not display anything. So if you set "Show Title" to "No", the module will be invisible.

Unique Features

  • Allow you to detect up to three different types of browsers (user agents).
  • Auto switching of templates based on the type of browsers.
  • A default template for use with all other browsers.

Download

How to install

  1. Download and install the "Auto Template Switcher" module.
  2. Make sure the module is published / enabled.
  3. Select a module position where you want to place the module.
  4. Edit the module in the Modules Manager.
  5. For the field "Show Title", select "No" - so that the module becomes invisible.
  6. Set the detect string (from $_SERVER['HTTP_USER_AGENT']) for browser 1, 2 and 3.
  7. Set the corresponding templates for each of the browswer.
  8. Also specify a template for the default browsewr. This will be used when there's no match with browser 1, 2 or 3.
  9. Click "Save" or "Apply".
  10. As highlighted above, for those using Joomla 1.5, you need to change one line in the Joomla core for this to work. In file /includes/application.php in function getTemplate (around line 289), change the line

    if ($template = $this->get('setTemplate')) {

    to this one

    if ($template = $this->getUserState('setTemplate')) {


Last Updated ( Monday, 01 September 2008 )
 

Comments  

 
# Paulo Barreto 2012-03-05 06:31
Hi,
Can I change the template according to the user group?

Tanks
 
 
# kksou 2012-03-05 17:22
Hi,

If you know PHP, almost anything is possible. You just need to code it.

For this module, as the name suggests, it just serve one simple purpose: to switch to a different template when you detect a user using iPhone.

I didn't code any other thing, so it won't respond to different user groups.

You might want to check the joomla.org to see if there's any plugin or module that achieve what you have in mind.

Regards,
/kksou
 
 
# raul lilloy 2012-05-10 06:08
Hi,
┐Could I use your program to backberry?
 
 
# kksou 2012-05-10 08:32
Hi,

Use $_SERVER ['HTTP_USER_AGENT '] to find out the appropriate user agent string and you should be able to use it.

Please refer to the section "How it works?" above.

Regards,
/kksou
 
 
# Toriano 2012-09-13 02:29
Can I use the 1.5 version on a 2.5 joomla website?
 
 
# kksou 2012-09-17 08:51
Hi,

Don't think so.

Sorry, still don't have the time to convert this for Joomla 2.5...

Regards,
/kksou
 
 
# devid 2012-11-02 02:30
:lol: :eek:
 
< Prev   Next >

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2015. kksou.com. All Rights Reserved