require('./include.php'); $xpx = 100; //分配變量(a,b),a爲模板中的變量名,b爲值 //[xpx] = 100 $smarty->assign('xpx',$xpx); // [ypx] => Array // ( // [app] => local // [host] => post // ) $smarty->assign('ypx',array('app' => 'local', 'host' => 'post')); //分配變量到模板 //(a,b),a爲模板中的索引數組變量名,b爲數組變量的元素所對應的值 //["Name"]=> array(1) { [0]=> string(4) "Fred" } // [Name] => Array // ( // [0] => Fred // ) $smarty->append('Name','Fred'); //數組的下標爲數組變量名, // // [name] => Array // ( // [0] => zhao // ) // // [age] => Array // ( // [0] => 20 // ) $smarty->append(array('name' => 'zhao', 'age' => 20)); // [user] => Array // ( // [0] => Array // ( // [name] => zhao // [age] => 20 // ) // ) $smarty->append('user',array('name' => 'zhao','age' => 20)); $smarty->display('db/math.html'); //顯示模板 //$smarty->clear_all_assign(); //清空smarty模板assign賦值的所有變量和值 $smarty->clear_assign("xpx"); //清除指定的assign分配的變量和值 //$smarty->clear_all_cache(); //清除所有模板的cache //$smarty->clear_cache(string template [, string cache id [, string compile id [, int expire time]]]); //清除指定模板的cache //$smarty->clear_compiled_tpl([string tpl_file]); //清除指定模板的編譯版本,如果不指定tpl_file,則表示清除所有已編譯模板 //$smarty->clear_config([string var]); //清除所有配置變量,如果指定了變量名稱,則只清除所指定的配置變量。 $arr = $smarty->get_template_vars(); //顯示模板中所有變量和值 echo '<pre>'; print_r($arr); echo '</pre>';