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>';
Smarty中的变量、方法(一)
最新推荐文章于 2017-01-07 16:01:32 发布
本文详细介绍了如何使用Smarty模板引擎分配变量,包括分配标量、数组变量,以及显示模板内容的方法,并展示了如何清空模板变量和清理缓存。
493

被折叠的 条评论
为什么被折叠?



