Code: Select all
if ( !isset($selected_template) ) $selected_template = "";
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);
}
Code: Select all
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {list_templates} plugin
*
* Type: function
* Name: list_templates
* Purpose: Prints the dropdowns for templates selection.
*
* ChangeLog?:
* 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
* Changed $_GET to $_REQUEST - more useful :)
* Added param $template_dir so you can specify where to search instead of using the smarty variable
* This is useful if you are using an array for your template directory
*
* @version 0.0.5.1
* @author Anton Blajev valqk@lozenetz.org - http://webreality.org hosting and web development
* @author Owen Cole owenc@totalsales.com - http://www.totalsales.com
* @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':
case 'template_dir':
$$_key = (string)$_value;
break;
default:
$smarty->trigger_error("[list_templates] unknown parameter $_key", E_USER_WARNING);
}
}
####################################################################
if ( !isset($selected_template) ) $selected_template = "";
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(isset($sort) && $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 ';
$get_params = "";
foreach($_REQUEST as $key => $val) {
if($key!="template") {
$get_params.="$key=$val&";
}
}
//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>Templates...</option>
';
$tpl_result .= smarty_function_html_options(array('output' => $tplDirs,
'values' => $tplDirs,
'selected' => $selected_template,
'print_result' => false),
$smarty);
$tpl_result .= '</select></form>';
return $tpl_result;
}
/* vim: set expandtab: */