Author Topic: I need the template switcher code  (Read 19140 times)

Offline tomhung

  • Posts: 348
I need the template switcher code
« on: December 14, 2006, 11:27:34 PM »
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

Offline oeh

  • Posts: 190
  • Gender: Male
  • German Pischer's, what's life without them?
Re: I need the template switcher code
« Reply #1 on: December 15, 2006, 01:03:14 PM »
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 ;-}>

Offline tomhung

  • Posts: 348
Re: I need the template switcher code
« Reply #2 on: December 15, 2006, 06:34:09 PM »
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!!
 

Offline Vincent

  • Posts: 376
  • Gender: Male
    • websites voor ondernemers
Re: I need the template switcher code
« Reply #3 on: December 15, 2006, 09:26:47 PM »
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
« Last Edit: December 15, 2006, 09:30:10 PM by vincent »

Offline marathoner

  • Posts: 495
Re: I need the template switcher code
« Reply #4 on: December 15, 2006, 10:07:41 PM »
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.
« Last Edit: December 16, 2006, 02:57:32 AM by marathoner »

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: I need the template switcher code
« Reply #5 on: December 16, 2006, 08:12:00 AM »
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

Offline tomhung

  • Posts: 348
Re: I need the template switcher code
« Reply #6 on: December 17, 2006, 07:48:19 PM »
thanks that exactly what i'm looking for.....

Offline DGEC

  • Posts: 388
  • Gender: Male
    • EbelTech homepage
Re: I need the template switcher code
« Reply #7 on: February 09, 2007, 04:25:57 PM »
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:
Code: [Select]
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:

Code: [Select]
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');

Offline marathoner

  • Posts: 495
Re: I need the template switcher code
« Reply #8 on: February 09, 2007, 08:55:15 PM »
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:
Code: [Select]
// 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

raspi

  • Guest
Re: I need the template switcher code
« Reply #9 on: February 20, 2007, 06:21:02 PM »
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.

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: I need the template switcher code
« Reply #10 on: February 20, 2007, 06:26:45 PM »
has not been done yet to my knowledge, but with the code here and reformating the output of the men calls you could achieve this functionality.

cheers

Klaus

raspi

  • Guest
Re: I need the template switcher code
« Reply #11 on: February 20, 2007, 08:34:58 PM »
Thx for the help - now I got it (at least the first step)
Now I only need to add a choose box for all installed templates.

For the ones looking for similar - here the code I used:
Code: [Select]
// get the template to display from URL
if ($_GET['template']!="") {
   if(file_exists(WB_PATH.'/templates/'.$_GET['template'].'/index.php')) {
      define('TEMPLATE',$_GET['template']);
  $_SESSION['TEMPLATE']=TEMPLATE;
}
}

// get the template to display from Session Variable
else {
if(isset($_SESSION['TEMPLATE']) AND $_SESSION['TEMPLATE'] != '')
define('TEMPLATE',$_SESSION['TEMPLATE']);
}

I just add another $SESSION variable.


Offline Vincent

  • Posts: 376
  • Gender: Male
    • websites voor ondernemers
Re: I need the template switcher code
« Reply #12 on: February 20, 2007, 08:43:01 PM »
That sounds interesting, raspi. Please let us know when it is up and running, I'd very much like to see it in action.

Good luck,
Vincent

Offline Luckyluke

  • Posts: 556
  • Gender: Male
  • Let's Rock
Re: I need the template switcher code
« Reply #13 on: April 26, 2009, 09:54:19 AM »
Hi,

This is an old post. But is this already developed?
Someone used this or any other code?
Or can this be done with a droplet? I see this droplet but I do not quite.

Grtz,
Luc

Offline Vincent

  • Posts: 376
  • Gender: Male
    • websites voor ondernemers
Re: I need the template switcher code
« Reply #14 on: April 26, 2009, 10:50:57 AM »
Hi Luc,

yes, the code as described in the post above works. I haven't tested the droplet, but it seems to do the same thing.

For implementing the code described in this post, change your root index file from
Code: [Select]
// Collect info about the currently viewed page
// and check permissions
$wb->get_page_details();
to
Code: [Select]
   // Collect info about the currently viewed page
    // and check permissions
    // 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']);
    }
    $wb->get_page_details();
and you're done. Call the template through www.yourdomain.com/?template=template-name


Regards,

Vincent

Offline Luckyluke

  • Posts: 556
  • Gender: Male
  • Let's Rock
Re: I need the template switcher code
« Reply #15 on: April 26, 2009, 08:27:05 PM »
Hi Vincent,

Thanks very much. And yes, this works!

Grtz,
Luc


Offline gottfried

  • Posts: 1339
Re: I need the template switcher code
« Reply #16 on: May 16, 2009, 06:45:39 PM »
Hi !  :-D

I extented the code above by


Code: [Select]

    // Display the filtered output on the frontend
        echo filter_frontend_output($frontend_output);


        // from here ,  Template switcher      -----------------------------------------------------------------

            echo "<body><html><div style='position: absolute; right: 0px ; top: 10px; width: 170px; height: 30px;' >" ;

            $return= '';
            $lineBreak = "\n";

            $lang_theme_selection = array(
              'reset_theme' => 'Standard-Design',
              'choose_theme' => 'W&auml;hle Design',
            );


            $CurrentTheme.="template=";

            // get list of available themes
                $value = $CONFIG['template'];
                $theme_dir = WB_PATH.'/templates/';



                $dir = opendir($theme_dir);
                while ($file = readdir($dir)) {
                    if (is_dir($theme_dir . $file) && $file != "." && $file != ".." && $file != 'CVS' && $file != 'sample' && $file != '.svn') {
                        $theme_array[] = $file;
                    }
                }
                closedir($dir);



            //start the output

                   $return.= $lineBreak . '<form name="ChooseTheme" id="ChooseTheme" action="' . $_SERVER['PHP_SELF'] . '" method="get" style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;display:inline">' . $lineBreak;
                   $return.= '<select name="ThemeSelect" class="listbox" onchange="if (this.options[this.selectedIndex].value) window.location.href=\'' . '?' . $CurrentTheme . '\' + this.options[this.selectedIndex].value;">' . $lineBreak;
                   $return.='<option selected="selected">' . $lang_theme_selection['choose_theme'] . '</option>';
                   foreach ($theme_array as $theme) {
                       $return.= '<option value="' . $theme . '"'.($value == $theme ? '  selected="selected"' : '').'>' . strtr(ucfirst($theme), '_', ' ') . ($value == $theme ? '  *' : ''). '</option>' . $lineBreak;
                   }

                      $return.=  '</select>' . $lineBreak;
                      $return.=  '</form>' . $lineBreak;


            echo $return;

            echo "</div></body></html>" ;

            // to here -> Templatewechsel Ende ------------------------------------------------------------------------
       



between

Code: [Select]
       echo filter_frontend_output($frontend_output);
and
Code: [Select]
  die; 
in the index.php of the wbroot









So you get a template switcher in the upper right corner of every wb-page

thanks for your code !



Offline lausianne

  • Posts: 206
    • Webdesign Burgdorf
Re: I need the template switcher code
« Reply #17 on: August 18, 2009, 02:41:02 PM »
Hi gottfried,

thanks a lot to you and the "above" coders. Really cool.
It took me a moment to figure out what you meant by "code above".
For others who don't get it right away:
1. Apply the replacement of $wb->get_page_details(); as described by Vincent
2. Add gottfrieds code

Any experiences with this in WB2.8? Or is there an even better option in 2.8?

Cheers,
Ralf.

pm. Added my personal reminder file to this post to slightly simplify copy/paste.



[gelöscht durch Administrator]
« Last Edit: August 18, 2009, 02:46:07 PM by lausianne »

Offline crnogorac081

  • Posts: 2002
  • Gender: Male
Re: I need the template switcher code
« Reply #18 on: October 29, 2009, 08:33:49 PM »
Hi,

I can ot find these lines :

Quote
between
Code:
        echo filter_frontend_out put($frontend_output);


and
Code:

  die; 

in wb 2.8 ?? any tips please ?


--- UPDATE:

Ok I just addet this to the end of file, just before ?> tag.. Is it ok ??

Now another question.. Since we are not calling the DB in this code, is there a way to filter somehow this ? For example to choose just a frontend templates..?? Because if you select background theme, the site will turn into white screen ??

cheers
« Last Edit: October 29, 2009, 08:47:20 PM by crnogorac081 »
UI / UX Designer

Offline ufferichter

  • Posts: 36
  • Gender: Male
    • websitebaker.dk
Re: I need the template switcher code
« Reply #19 on: February 11, 2011, 04:26:14 PM »
I try to edit the index.php, but i dont know about the code         echo filter_frontend_out put($frontend_output);

Where to go
Regards Uffe

WebsiteBaker.dk

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: I need the template switcher code
« Reply #20 on: February 11, 2011, 05:12:50 PM »
That block of code is just to create a list of templates to  switch.
Do not put that in your root/index.php but somewhere in your template.

Only the code in this post should be in the root/index.php

Offline ufferichter

  • Posts: 36
  • Gender: Male
    • websitebaker.dk
Re: I need the template switcher code
« Reply #21 on: February 11, 2011, 05:54:15 PM »
Yes i understand, but not sure where in the php i can set ind the code "echo filter_frontend_out put($frontend_output);"

I just put it my testpage here http://testzone.uffe.it/
Regards Uffe

WebsiteBaker.dk

Offline ufferichter

  • Posts: 36
  • Gender: Male
    • websitebaker.dk
Re: I need the template switcher code
« Reply #22 on: February 12, 2011, 06:24:30 PM »
Hi Ruud, do you know something about this, my topic before
Regards Uffe

WebsiteBaker.dk

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: I need the template switcher code
« Reply #23 on: February 12, 2011, 10:06:49 PM »
I tried explaining before.
You do not need that code, only the code that was explained in this single post

Switching the template is done by calling: http://www.website.com?template=round

Offline ufferichter

  • Posts: 36
  • Gender: Male
    • websitebaker.dk
Re: I need the template switcher code
« Reply #24 on: February 13, 2011, 05:09:53 AM »
I was not explaining good, so if you look https://forum.WebsiteBaker.org/index.php/topic,4887.msg85174.html#msg85174 thats the solution i am looking for
Regards Uffe

WebsiteBaker.dk