Ok, I am learning to handle smarty slowly but fail to see how I should use this code? If anyone can point me in the right direction I would apreciate it.
Code:<?php /** * Smarty plugin * @package Smarty * @subpackage plugins */ /** * Smarty {list_templates} plugin * * Type: function<br> * Name: list_templates<br> * Purpose: Prints the dropdowns for templates selection. * * ChangeLog:<br> * Removed some useless assgned vars. * Changed to get the selected template from $template assigned from the template, not from $_GET! * Removed associative array keeping path=>name, names are == to paths when setting $smarty->template_dir * @version 0.0.4 * @author Anton Blajev * @param string * @param Smarty * @return string */ function smarty_function_list_templates($params, &$smarty) { require_once $smarty->_get_plugin_filepath('function','html_options'); /* Default values. */ foreach ($params as $_key=>$_value) { switch ($_key) { case 'selected_template': case 'sort': case 'template': $$_key = (string)$_value; break; default: $smarty->trigger_error("[list_templates] unknown parameter $_key", E_USER_WARNING); } } #################################################################### if($template_dir=="") { $template_dir=$smarty->template_dir; } $tplDirs=array(); if($dtpl = opendir("$template_dir")) { while(false !== ($dir = readdir($dtpl))) { if(is_dir($template_dir."/".$dir) && $dir!="." && $dir!="..") { array_push($tplDirs,"$dir"); } } closedir($dtpl); } if($sort==1) { sort($tplDirs); } if(sizeof($tplDirs)<1) { $tplDirs[" "]="No templates found in $template_dir."; } /* I see no point in this, if the path and name are different, yes but not in my case, when I set $smarty->template_dir where my tpls are it's pointless to keep them in bigger array! */ /* $tplName=array(); $tplPath=array(); foreach($tplDirs as $key => $val) { array_push($tplName, $key); array_push($tplPath, $val); } */ $tpl_result .= '<form name=template_select method=post> '; $tpl_result .= '<select name=template '; foreach($_GET as $key => $val) { if($key!="template") { $get_params.="$key=$val"; } } if($get_params!="") $get_params.="&"; echo "TPL VAR: ".$smarty->get_template_vars('template')."<br>"; if($smarty->get_template_vars('template')) { $selected_template=$smarty->get_template_vars('template'); } $tpl_result .="onChange=\"return self.location.href='".$_SERVER[PHP_SELF]."?".$get_params."template='+document.template_select.template.value+'';\""; $tpl_result .='> <option> </option> '; $tpl_result .= smarty_function_html_options(array('output' => $tplDirs, 'values' => $tplDirs, 'selected' => $selected_template, 'print_result' => false), $smarty); $tpl_result .= '</select></form>'; $html_result .= $tpl_result; return $html_result; } /* vim: set expandtab: */ ?>



and adds JS so you can switch between templates degining template=$TEMPLATE.

Bookmarks