1 / 4
文档名称:

PHP Smarty快速入门.doc

格式:doc   大小:20KB   页数:4页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

PHP Smarty快速入门.doc

上传人:zbfc1172 2019/5/21 文件大小:20 KB

下载得到文件列表

PHP Smarty快速入门.doc

文档介绍

文档介绍:复制代码代码如下:<!DOCTYPEHTMLPUBLIC"-//W3C////EN""/html4/"> <html> <head> <metahttp-equiv="Content-Type"content="text/html;charset=gb2312"> <title>Smarty</title> </head> <body> {$hello} </body> </html>,将此文件放在learn/下: 复制代码代码如下:<?php //引用类文件 require'smarty/libs/'; $smarty=newSmarty; //设置各个目录的路径,这里是安装的重点 $smarty->template_dir="smarty/templates/templates"; $smarty->compile_dir="smarty/templates/templates_c"; $smarty->config_dir="smarty/templates/config"; $smarty->cache_dir="smarty/templates/cache"; //smarty模板有高速缓存的功能,如果这里是true的话即打开caching,但是会造成网页不立即更新的问题,当然也可以通过其他的办法解决 $smarty->caching=false; $hello="HelloWorld!"; //赋值 $smarty->assign("hello",$hello); //引用模板文件 $smarty->display(''); ?>(3)!了。   在模板文件中需要替换的值用大括号{}括起来,值的前面还要加$号。例如{$hello}。这里可以是数组,比如{$},{$}… 而PHP源文件中只需要一个简单的函数assign(var,value)。 简单的例子: *.tpl: Hello,{$}!Good{$} *.php: $hello[name]=“”; $hello[time]=”morning”; $smarty->assign(“exp”,$hello); output: Hello,!Goodmorning  网站中的网页一般header和footer是可以共用的,所以只要在每个tpl中引用它们就可以了。 示例:*.tpl: {includefile=""} {*bodyoftemplategoeshere*} {includefile=""}   模板文件中可以使用ifelse等判断语句,即可以将一些逻辑程序放在模板里。"eq","ne","neq","gt","lt","lte","le","gte""ge","iseven","isodd","isnoteven","isnotodd","not","mod","divby","evenby","oddby","==","!="