WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: glenpig on February 08, 2014, 03:48:14 PM

Title: Template Switching in v2.8.3
Post by: glenpig 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.
Title: Re: Template Switching in v2.8.3
Post by: nibz on February 08, 2014, 04:38:19 PM
Quote from: http://www.wbhulp.nl/posts/vanuit-de-website-een-ander-template-kiezen/  translated from dutch to english
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']);
}
Title: Re: Template Switching in v2.8.3
Post by: glenpig 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.
Title: Re: Template Switching in v2.8.3
Post by: nibz 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
Title: Re: Template Switching in v2.8.3
Post by: nibz 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']);
}
Title: Re: Template Switching in v2.8.3
Post by: glenpig 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!