您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php开发之smarty1

2024/4/11 1:38:20发布23次查看
php开发之smarty一
关于smarty的配置在这里就不说了。这里就说一下其中的两个函数。
(1) assign 方法
assign 用于在模版被执行时为模版变量赋值,语法格式如下:
{assign var =”” value =”“}
参数var为被赋值的变量名,参数value是赋给变量的值。
(2)display方法
display 用来显示模版,需要制定一个合法的模版资源的类型和路径。
语法格式如下:
void display(string template[,string cache_id[,string compile_id]])
参数cache_id 为可选参数,用于指定缓存号。参数compile_id为可选参数用于指定一个编译号。编译号可以将一个模版编译成不同的版本使用。例如,可针对不同的语言编译模版。编译号的另一个作用,如果存在多个 templatedir模版目录,但是只有一个compile_dir 编译后存档目录,这是可以为每一个 templatedir模版目录制定一个编译号,以避免相同的模版文件在编译后相互覆盖。相对于在每一次调用display()时都指定编译号,也可以通过设置compile_id 编译号属性来一次性设定。
示例代码如下:
template_dir =base_path.smarty_path.'templates/';$smarty->compile_dir =base_path.smarty_path.'templates_c/';$smarty->config_dir =base_path.smarty_path.'configs/';$smarty->cache_dir =base_path.smarty_path.'cache/';//使用smarty 赋值方法将一对名称/方法发送到模版中$smarty->assign('title','jack 的第一个smarty程序');$smarty->assign('content','hello welcome to study smarty');//显示模版$smarty->display('index.html');?>
运行结果如下:
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product