一起学习网 一起学习网


smarty简单模板变量输出方法 原创

网络编程 smarty简单模板变量输出方法 原创 06-22

本文简单讲述了Smarty的模板变量输出方法。分享给大家供大家参考,具体如下:

config.inc.php配置文件如下:

include_once('smarty/Smarty.class.php');
$smarty=new Smarty();
$smarty->config_dir="smarty/Config_File.class.php";
$smarty->caching=false; //是否开启缓存
$smarty->template_dir="./templates"; //模板目录
$smarty->compile_dir="./templates_c"; //编译目录
$smarty->cache_dir="./smarty_cache"; //缓存目录
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";

index.php文件如下:

include('./config.inc.php');
$title="php测试标题";
$content="smarty练习!";
$newstext[]=array("name"=>"php程序测试","date"=>"2015-08-01");
$newstext[]=array("name"=>"php视频教程","date"=>"2015-08-02");
$newstext[]=array("name"=>"smarty学习","date"=>"2015-08-03");
$row=array("标题","姓名","年龄");
$smarty->assign("title",$title);
$smarty->assign("row",$row);//一个数组传递多个值
$smarty->assign("shownewstext",$newstext);//二维数组传递多个值
$smarty->assign("content",$content);
$smarty->display('index.htm');

运行结果如下:

测试数组:标题 | 姓名 | 年龄 
--------------------------------------------------------------------------------
测试内容为:smarty练习! 
循环新闻内容为:
php程序测试 - 2015-08-01
php视频教程 - 2015-08-02
smarty学习 - 2015-08-03

希望本文所述对大家基于Smarty模板的php程序设计有一定帮助作用。

php解析xml 的四种简单方法(附实例)
XML处理是开发过程中经常遇到的,PHP对其也有很丰富的支持,本文只是对其中某几种解析技术做简要说明,包括:Xmlparser,SimpleXML,XMLReader,DOMDocument。1。XM

WordPress过滤垃圾评论的几种主要方法小结
由于个人博客小站的空间与mysql空间往往有限,共享服务器资源也有限,所以垃圾评论一定要拦截在写入数据库之外。更可气的是看到空间的统计,很几

微信支付开发交易通知实例
一、交易通知用户在成功完成支付后,微信后台通知(POST)商户服务器(notify_url)支付结果。商户可以使用notify_url的通知结果进行个性化页面的展示


编辑:一起学习网

标签:测试,数组,通知,多个,对其