I need the template switcher code

raspi

Does somebody know a way to permanently change the tempalte also for the other pages of a site.
Let's say somewhere I put a dropdown box on the "Home" page - the user switches to another template and from now on (for this browser session only) - he surfs the site with the chosen template.

Like to online test of Joomla for example. That would be a good way to demonstrate different templates to a Customer.

marathoner

Simply insert the 3 lines of code that I mentioned above in your wb/index.php file. I inserted the code between "$wb->page_select() or die();" and "$wb->get_page_details();". Here's a snippet from my wb/index.php file:

// Figure out which page to display
// Stop processing if intro page was shown
$wb->page_select() or die();

// Figure out what template to use - DFD allows 'template' variable in the URL to call a different template
if ($_GET['template']!="")
if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php'))
define('TEMPLATE',$_GET['template']);

// Collect info about the currently viewed page
// and check permissions
$wb->get_page_details();


To use this feature simply append the TEMPLATE variable to your URL to let it know which template you want to display that page with. For example, to display your home page using the ALLCSS template you would enter your URL into your browser as:
http://www.mydomain/pages/home.php?template=allcss

DGEC

I cannot figure out what's up with this, not sure where to put this in the index file. How does this work?  I thought that it should just redefine the value in the TEMPLATE variable.

Where does TEMPLATE get loaded then?

I've tried it before and after the existing code:
require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');

I've tried putting it in an IF statement, copying the require, echo'd the results...

The other template is found in correct directory & displays if echoed, but nothing will change my existing template display.

Tried putting the existing "require" as an else to the template != and the page is empty - nothing but the body. I thought maybe the define was creating a constant, so I added it too...

At first I was putting it in the active template's index.php itself, which didn't work either.

Here's what I've put in the main wb/index.php file:

if ($_GET['template']!="") {
   if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php')) 
   {
      define('TEMPLATE',$_GET['template']);
require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');
   }
}

require(WB_PATH.'/templates/'.TEMPLATE.'/index.php');

tomhung

thanks that exactly what i'm looking for.....

kweitzel

I don't know about session variables, but what you could actually do is modify the menu output to display the template part to achieve this (as a temporary workaround).

cheers

Klaus

marathoner

#5
Insert the following snippet in the root directory index(.)php

if ($_GET['template']!="")
   if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php'))
      define('TEMPLATE',$_GET['template']);

Now just call your page as:
http://www.domainname.com/index.php?template=simple

Beware that this is NOT persistent. I've been wanting to make use of session variables so that things like using different templates or different CSS can be persistent. If anyone out there knows how to use the WB session management to set and read a new session variable I'd like to know how to do this.

Vincent

#4
Hi Greg,

If I understand your problem correctly, I think I had the same wish, and did a lot of thinking about it.

Eventually I found this (somewhat complex) solution:


  • I did 2 installations, one in the root, and one in root/wb.
  • Then I adjusted the index files of all templates I wanted to show, so they would only show from menu level 2.
  • I prepared one complete site in root/wb/
  • with page cloner I copied all files of one 'site', so you get design 1 /page 1/page 2/page2b etc. And design2/ page1/page2/page2b etc. Each page needs to have its own template assigned
  • in the root installation I made links to the wb -installation, like design 1, design 2 etc.
  • So if you click on one such link, it will open the design with all content, starting from level page1, page2 etc. in a new window

It works.
Hope you understand my approach and hopefully it is of some help to you.
If someone has a better (faster) idea, let me know.

Regards,

Vincent

tomhung

That is awesome!!!  But it's not what I need. 

I have highly customized templates specific to this site.  I would like the customer to be able to switch them without logging in and changing the DB entry.  The reason is that I want them to see the site with their content, logo, etc. 

I would like to be able to send them three links like this:
http://addons.websitebaker.org/pages/templates.php?template=uccellini
http://addons.websitebaker.org/pages/templates.php?template=reflection
http://addons.websitebaker.org/pages/templates.php?template=kirche

but of my site!!

oeh

Hi there tomhung.

I think what you are loocking for is this.

could be of help, have a look  at his page ;-)

http://slink2.no-ip.info:82/wsb/pages/wb-ideas/test-pages/template-test.php

Regards
OEH
oeh ;-}>

tomhung

OK... I've been developing a site with a couple different template options.  I haven't shown the customer (my bosses) the templates yet.  I would like to be able to send links to them for preview.  Thus I would like some code similar to http://addons.websitebaker.org/pages/templates.php

I'm guessing this request goes to Klaus and Matthias....

Greg