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')) {



User reviews   Average user ratings:    4.5   (from 6 users)
  1. Wayne Geddings
    September 18, 2008 11:07pm
    Possible?

    The perfect extension would be a plugin that sent any mobile visitor to the designated Home Mobile page and adjusted for the browser (IE, Firefox, Google Chrome, etc.

  2. kksou
    September 24, 2008 12:44am

    Hi Wayne,

    Please try the latest version v1.01 (for Joomla 1.0) and v1.51 (for Joomla 1.5).

    I've incorporated this feature into the new version i.e. you can now specify the inital designated page that will be displayed when a template-switch occurs

    Regards,
    /kksou

  3. dave
    September 27, 2008 8:00am
    not working for me

    I use jomla 1 , after 2 hours can't manage to make it work, install was fine, module is publish, can't find why it's not working www.api4.me/joomla/ thanks for helping

  4. dave
    September 27, 2008 8:37am
    worse on another site

    If I publish the module, the site doesn't work at all anymore

  5. kksou
    September 27, 2008 9:43am

    What's the error message that you get? Please provide some details so that we have some clues as to what might have happened.

    1. Can you please try on a fresh install of Joomla first. Did it work?

    Try this first so that at least you'll know if it works on your machine.

    2. If (1) works, try it on your other site that you said didn't work. Please list the entries that you've entered in the parameters page. e.g. user_agent1=?, template1=?, user_agent2=?, template2=?, etc. Please also list the names of the folders in the folder /templates

    Regards,
    /kksou

  6. dave
    September 28, 2008 12:45am
    about the site

    thanks for the answer
    here it is http://www.api4.me/joomla/switcher.jpg
    this was done on a fresh install of joomla, i don't have any error message, the template just doesnt switch on IE,fox or Iphone
    I will try reinstalling a new version of joomla
    thanks for the help

Note: You have to be a registered member to leave a comment. Free registration here.

Last Updated ( Monday, 01 September 2008 )
 
< Prev   Next >

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