Snippet name: Template Switcher
Author: Nick_NP
Version: 1.0 (Final)
More info: <a href="http://www.etomite.com/browsesnippets.html?int_snipid=127">View this snippet</a>
Description:
Generates a drop-down menu from which users can choose which template to view your site with.
Please feel free to comment on this snippet, suggest improvements, or simply praise my work!
WARNING : For this snippet to work as intended, you'll need to edit Etomite's index.php. Has only been tested with Etomite v0.6.
The code to be insterted is between the long lines (---------------------------), colour in a code block doesn't seem to work for me.... (Around line #737)
 // get the template and start parsing!
 $sql = "SELECT * FROM ".$this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_templates WHERE ".$this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_templates.id = '".$this->documentObject['template']."';";
 $result = $this->dbQuery($sql);
 $rowCount = $this->recordCount($result);
 if($rowCount!=1) {
  $this->messageQuit("Incorrect number of templates returned from database", $sql);
 }
 $row = $this->fetchRow($result);
   // ----------------------------------------------------------------------
// TemplateSwitcher Mod
   if ( ( substr($row['templatename'],0,1) == '_' ) && ( ( session_is_registered('user_templateid') ) || ( isset($_POST['templateid']) ) ) )
   {
    if ( isset($_POST['templateid']) )
     $newtemplate = $_POST['templateid'];
    else
     $newtemplate = $_SESSION['user_templateid'];
   $sql = "SELECT * FROM ".$this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_templates WHERE ".$this->dbConfig['dbase'].".".$this->dbConfig['table_prefix']."site_templates.id = '".$newtemplate."';";
   $result = $this->dbQuery($sql);
   $rowCount = $this->recordCount($result);
   if($rowCount!=1) {
   $this->messageQuit("Incorrect number of templates returned from database", $sql);
   }
   $row = $this->fetchRow($result);
   }
   // ----------------------------------------------------------------------
   $documentSource = $row['content'];
 // get snippets and parse them the required number of times
 $this->snippetParsePasses = empty($this->snippetParsePasses) ? 3 : $this->snippetParsePasses;
And here's the snippet code :
session_start();
$output = "";
if ( isset($_POST['templateid']) )
{
 session_register( "user_templateid" );
 $_SESSION['user_templateid'] = $_POST['templateid'];
}
$query = "";
$query .= "select * from ".$etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix']."site_templates ";
$query .= "where ".$etomite->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix']."site_templates.templatename like '\_%';";
$templatelist = $etomite->dbQuery($query);
$output .= '<form action="" method="post">';
$output .= '<label>theme » ';
$output .= '<select name="templateid">';
while ( $template = $etomite->fetchRow($templatelist) )
{
 $output .= '<option value="'.$template['id'].'" '.(($_SESSION['user_templateid']==$template['id'])?'selected':'').'>'.substr($template['templatename'],1).'</option>';
}
$output .= '</select>';
$output .= '</label>';
$output .= '<input type="submit" value="Go" />';
$output .= '</form>';
return $output;
Using TemplateSwitcher :
All templates that you want your users to be able to choose between must have a name starting with an underscore
ex : "_blue template" (chosen template will not be applied on pages whose template in Etomite does not start with an undescore)
Remember to include the snippet in all templates whose names start with an underscore!
Page caching must be turned OFF on all pages using the snippet! (sorry, haven't found a way around that...)
Enjoy!
Edited by Nick_NP, 23 July 2005 - 09:42 AM.










