Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 01:25:51 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155555 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1] 2   Go Down
Print
Author Topic: I need the template switcher code  (Read 8337 times)
tomhung

Offline Offline

Posts: 353


« 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
Logged
oeh

Offline Offline

Posts: 190



« 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 wink

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

Regards
OEH
Logged

Good bye ;-{(
oeh ;-}>
tomhung

Offline Offline

Posts: 353


« 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!!
 
Logged
Vincent

Offline Offline

Posts: 360


WWW
« 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 » Logged
marathoner

Offline Offline

Posts: 495


« 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 » Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6977


WWW
« 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
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

tomhung

Offline Offline

Posts: 353


« Reply #6 on: December 17, 2006, 07:48:19 PM »

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

Offline Offline

Posts: 386


WWW
« 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:
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:
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');
Logged
marathoner

Offline Offline

Posts: 495


« 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:
// 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
Logged
raspi

Offline Offline

Posts: 3


« 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.
Logged
kweitzel
Forum administrator
*****
Offline Offline

Posts: 6977


WWW
« 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
Logged

WebsiteBaker Org e.V. - for WebsiteBaker

raspi

Offline Offline

Posts: 3


« 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:
// 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.

Logged
Vincent

Offline Offline

Posts: 360


WWW
« 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
Logged
Luckyluke

Offline Offline

Posts: 555



« Reply #13 on: April 26, 2009, 08: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
Logged
Vincent

Offline Offline

Posts: 360


WWW
« Reply #14 on: April 26, 2009, 09: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:
// Collect info about the currently viewed page
// and check permissions
$wb->get_page_details();
to
Code:
   // 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
Logged
Luckyluke

Offline Offline

Posts: 555



« Reply #15 on: April 26, 2009, 07:27:05 PM »

Hi Vincent,

Thanks very much. And yes, this works!

Grtz,
Luc

Logged
gottfried

Offline Offline

Posts: 981


« Reply #16 on: May 16, 2009, 05:45:39 PM »

Hi !  grin

I extented the code above by


Code:

    // 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:
       echo filter_frontend_output($frontend_output);

and
Code:
  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 !


Logged
lausianne
WebsiteBaker Org e.V.

Offline Offline

Posts: 155


WWW
« Reply #17 on: August 18, 2009, 01: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.

« Last Edit: August 18, 2009, 01:46:07 PM by lausianne » Logged
crnogorac081
AddOn Development
*
Offline Offline

Posts: 1706



« 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 » Logged

Wow, I coded something myself: PM Messanger Modul ,Searchbox with suggestions
ufferichter

Offline Offline

Posts: 36


WWW
« 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
Logged

Regards Uffe

websitebaker.dk
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2298



WWW
« 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
Logged

Professional WebsiteBaker Solutions
ufferichter

Offline Offline

Posts: 36


WWW
« 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/
Logged

Regards Uffe

websitebaker.dk
ufferichter

Offline Offline

Posts: 36


WWW
« Reply #22 on: February 12, 2011, 06:24:30 PM »

Hi Ruud, do you know something about this, my topic before
Logged

Regards Uffe

websitebaker.dk
Ruud
WebsiteBaker Org e.V.

Offline Offline

Posts: 2298



WWW
« 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
Logged

Professional WebsiteBaker Solutions
ufferichter

Offline Offline

Posts: 36


WWW
« Reply #24 on: February 13, 2011, 05:09:53 AM »

I was not explaining good, so if you look http://www.websitebaker2.org/forum/index.php/topic,4887.msg85174.html#msg85174 thats the solution i am looking for
Logged

Regards Uffe

websitebaker.dk
Pages: [1] 2   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!