WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Templates, Menus & Design => Topic started by: tomhung on December 14, 2006, 11:27:34 PM

Title: I need the template switcher code
Post by: tomhung 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
Title: Re: I need the template switcher code
Post by: oeh 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
Title: Re: I need the template switcher code
Post by: tomhung 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!!
 
Title: Re: I need the template switcher code
Post by: Vincent 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:


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
Title: Re: I need the template switcher code
Post by: marathoner 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.
Title: Re: I need the template switcher code
Post by: kweitzel 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
Title: Re: I need the template switcher code
Post by: tomhung on December 17, 2006, 07:48:19 PM
thanks that exactly what i'm looking for.....
Title: Re: I need the template switcher code
Post by: DGEC 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');
Title: Re: I need the template switcher code
Post by: marathoner 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
Title: Re: I need the template switcher code
Post by: raspi 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.
Title: Re: I need the template switcher code
Post by: kweitzel 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
Title: Re: I need the template switcher code
Post by: raspi 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.

Title: Re: I need the template switcher code
Post by: Vincent 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
Title: Re: I need the template switcher code
Post by: Luckyluke 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 (http://www.websitebakers.com/pages/droplets/official-library/other/template-tester.php) but I do not quite.

Grtz,
Luc
Title: Re: I need the template switcher code
Post by: Vincent 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
Title: Re: I need the template switcher code
Post by: Luckyluke on April 26, 2009, 08:27:05 PM
Hi Vincent,

Thanks very much. And yes, this works!

Grtz,
Luc

Title: Re: I need the template switcher code
Post by: gottfried 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

(http://www.channel-1.de/tests/templatetest5.jpg)

(http://www.channel-1.de/tests/templatetest6.jpg)

(http://www.channel-1.de/tests/templatetest7.jpg)

(http://www.channel-1.de/tests/templatetest8.jpg)

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

thanks for your code !


Title: Re: I need the template switcher code
Post by: lausianne 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]
Title: Re: I need the template switcher code
Post by: crnogorac081 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
Title: Re: I need the template switcher code
Post by: ufferichter 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
Title: Re: I need the template switcher code
Post by: Ruud 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 (https://forum.WebsiteBaker.org/index.php/topic,4887.msg83640.html#msg83640) should be in the root/index.php
Title: Re: I need the template switcher code
Post by: ufferichter 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/
Title: Re: I need the template switcher code
Post by: ufferichter on February 12, 2011, 06:24:30 PM
Hi Ruud, do you know something about this, my topic before
Title: Re: I need the template switcher code
Post by: Ruud 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 (https://forum.WebsiteBaker.org/index.php/topic,4887.msg83640.html#msg83640)

Switching the template is done by calling: http://www.website.com?template=round
Title: Re: I need the template switcher code
Post by: ufferichter 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 (https://forum.WebsiteBaker.org/index.php/topic,4887.msg85174.html#msg85174) thats the solution i am looking for
Title: Re: I need the template switcher code
Post by: Ruud on February 13, 2011, 11:13:02 PM
That block does not do the switching, it is just a list that will use the function I pointed yo you.

The list will not work properly in WB2.8.x because now there are also backend themes.
The list could created manually just like any other form that uses a select (method GET).

First start with the code for the index.php. Try to see if it works by typing on the addressbar website.com?template=round.
If that works, you could think of the next step..
Title: Re: I need the template switcher code
Post by: ufferichter on February 15, 2011, 03:45:39 PM
If it so, that the list will not work properly in WB2.8.x, i think this is a petty, i will hope that will be possible to make a solution with dropdown box, every cms have it.

If any can make a template switcher in a dropdownbox, that will be great
Title: Re: I need the template switcher code
Post by: Ruud on February 15, 2011, 03:53:45 PM
You can just create the dropdown manually..

I do not assume you add many templates on a regular basis.. So the list using the templates you want to offer to the visitors should not have to be "generated".
Title: Re: I need the template switcher code
Post by: ufferichter on February 16, 2011, 08:19:46 PM
Hi Ruud

Ok i try to listen after now!

I incert the chances in index.php on my testsite, and try to call this url http://testzone.uffe.it/?template=round and the template was chance allright.,., please note that not the official site og WebsiteBaker in Denmark, but only where i am testing!

What i am doing next to make a dropdown manualy.
Title: Re: I need the template switcher code
Post by: ufferichter on February 20, 2011, 10:49:45 PM
Ruud, are you still with me?
Title: Re: I need the template switcher code
Post by: Ruud on February 21, 2011, 10:26:17 PM
I had the impression it would be clear now.
Create a small form somewhere in your template (where you want it to show up) that creates the links to another template.
Code: (Untested example) [Select]
<form name="myform" method="get" action="">
  <select name="template" onchange="javascript: document.myform.submit();">
    <option value="round">The nice Round template</option>
    <option value="allcss">Only using CSS</option>
    <option value="someother">Some other template</option>
  </select>
</form>
Replace the option values by your installed template directory names.
Title: Re: I need the template switcher code
Post by: ufferichter on February 22, 2011, 12:43:44 AM
Hi Ruud

Yes its working, but have to install the form on every theme you wanna to show, i cant understand there not a a modul there is working all over.

But Ruud, i got a problem now, i was not thinking, so i choose the theme argos_theme, and now my site is gone, i have tryed to find the cookie but no luck, and remove my my old ie temp file, do you have a solution..
Title: Re: I need the template switcher code
Post by: Ruud on February 22, 2011, 10:16:12 AM
Adding it to each template is one option. The discussion earlier in this tread was to put it in your main index.php.
The problem there is that you cannot tell where the dropdownlist will show up in the selected template.
Since the template switcher is a modification in the core files it makes no sense to create a module for it. The module would not function without modifying the core files.

The theme is stored in a session, so if you close your browser (all instances) and retry with a new browserwindow it should show your original template again.
Title: Re: I need the template switcher code
Post by: ufferichter on February 25, 2011, 02:12:17 AM
Hi Ruud

Yes i understand, but i must say, its not the prober solution for me, and if its not possible to make a modul for that, i must say, its a petty...

But thanks for helping me...
Title: Re: I need the template switcher code
Post by: Boudi on September 07, 2011, 02:40:20 PM
Easiest way is:

create some templates (eg: yellow, red)
create some homepages (eg: home_yellow, home_red)
link every homepage to it's own template
Place in every index.php from each template a pulldownmenu like:

HEAD:
Code: [Select]
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
<!--

function openURI() {
var control = document.name.templates;
if (control.options[control.selectedIndex].value != '') {
location.href = control.options[control.selectedIndex].value;
}
}

//-->
</SCRIPT>

BODY:
Code: [Select]
<FORM ACTION="" NAME="name">
<SELECT NAME="templates" onchange="openURI()">
<OPTION VALUE="home_yellow.php" selected="selected">Template 1</OPTION>
<OPTION VALUE="home_red.php">Template 2</OPTION>
</SELECT>
</FORM>

Don't forget to change the SELECTED into the template that is show at that moment.