I need the template switcher code

Boudi

#35
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:
<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:
<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.
...:: Bake the Unbakable ::...

ufferichter

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...
Regards Uffe

WebsiteBaker.dk

Ruud

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.
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

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..
Regards Uffe

WebsiteBaker.dk

Ruud

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.
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

Regards Uffe

WebsiteBaker.dk

ufferichter

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.
Regards Uffe

WebsiteBaker.dk

Ruud

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".
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

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
Regards Uffe

WebsiteBaker.dk

Ruud

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..
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

Regards Uffe

WebsiteBaker.dk

Ruud

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
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

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

WebsiteBaker.dk

ufferichter

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

Ruud

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
[url=https://dev4me.com/modules-snippets/]Dev4me - WebsiteBaker modules[/url] - [url=https://wbhelp.org/]WBhelp.org[/url]

ufferichter

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

crnogorac081

#19
Hi,

I can ot find these lines :

Quote
between
Code:
       echo filter_frontend_output($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
Web developer

lausianne

#18
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]

gottfried

Hi !  :-D

I extented the code above by




   // 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

       echo filter_frontend_output($frontend_output);

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



Luckyluke

Hi Vincent,

Thanks very much. And yes, this works!

Grtz,
Luc


Vincent

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

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

to

   // 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

Luckyluke

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

Vincent

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

raspi

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:

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


kweitzel

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