Author Topic: Template Switching in v2.8.3  (Read 3665 times)

Offline glenpig

  • Posts: 6
Template Switching in v2.8.3
« on: February 08, 2014, 03:48:14 PM »
Hi Everyone

We've just upgraded our version of WB to 2.8.3.

In our previous version we added a mobile detect script which set the template to www.url.com/?template=mobile which then displayed a mobile version of the web site.

It doesn't seem to be possible to do this in v2.8.3??? Before you could add "?template=xxxxx" to the end of any page URL and it would switch to that template but this isn't working in 2.8.3

I have installed the templates ok so the directories, files and settings etc are all there.

Any help would be greatly appreciated.

Offline nibz

  • Posts: 684
  • Gender: Male
Re: Template Switching in v2.8.3
« Reply #1 on: February 08, 2014, 04:38:19 PM »
Add the next code in your root index.php before
$wb->get_page_details();

Code: [Select]
// Sticky Template switcher
if ($_GET['template']!="") {  // get the template to display from URL
   if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php')) {
      define('TEMPLATE',$_GET['template']);
      $_SESSION['TEMPLATE']=TEMPLATE;
    }
} else {   // else get the template to display from Session Variable
    if(isset($_SESSION['TEMPLATE']) AND $_SESSION['TEMPLATE'] != '')
        define('TEMPLATE',$_SESSION['TEMPLATE']);
}

Offline glenpig

  • Posts: 6
Re: Template Switching in v2.8.3
« Reply #2 on: February 08, 2014, 06:13:26 PM »
Thanks nibz - that's perfect.

The only thing I'm now getting is a redirection error "too many server redirects" when visiting the site via an Android device. Which is something we didn't get on the previous WB version.

Offline nibz

  • Posts: 684
  • Gender: Male
Re: Template Switching in v2.8.3
« Reply #3 on: February 08, 2014, 07:44:34 PM »
1: clear browser cache -> try again.

2: if that doesn't work post the .htaccess content here

Offline nibz

  • Posts: 684
  • Gender: Male
Re: Template Switching in v2.8.3
« Reply #4 on: February 13, 2014, 05:19:01 PM »
To no longer display an php notice update the script to:

Code: [Select]
// Sticky Template switcher
if (isset($_GET['template'])) {  // get the template to display from URL
   if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php')) {
      define('TEMPLATE',$_GET['template']);
      $_SESSION['TEMPLATE']=TEMPLATE;
    }
} else {   // else get the template to display from Session Variable
    if(isset($_SESSION['TEMPLATE']) AND $_SESSION['TEMPLATE'] != '')
        define('TEMPLATE',$_SESSION['TEMPLATE']);
}

Offline glenpig

  • Posts: 6
Re: Template Switching in v2.8.3
« Reply #5 on: February 14, 2014, 04:55:12 PM »
Thanks for all your help nibz

All seems to be working now!

I had ordered the code so that the mobile detect script was included before your sticky template script. Looking back at the previous WB that we were using, it was the other way around (sticky template first followed by mobile detect).

So I swapped the order over and all seems to be working well now!

 

postern-length