找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1415|回复: 0
打印 上一主题 下一主题

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

[复制链接]

2647

主题

2647

帖子

7881

积分

论坛元老

Rank: 8Rank: 8

积分
7881
跳转到指定楼层
楼主
发表于 2018-2-14 05:34:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            本文简单讲述了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="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程序设计有一定帮助作用。
            
            
您可能感兴趣的文章:
  • smarty模板中使用get、post、request、cookies、session变量的方法
  • smarty模板引擎中变量及变量修饰器用法实例
  • PHP模板引擎Smarty中变量的使用方法示例
  • PHP模板引擎Smarty之配置文件在模板变量中的使用方法示例
  • PHP模板引擎Smarty中的保留变量用法分析
  • PHP模板引擎Smarty自定义变量调解器用法
  • PHP模板引擎Smarty内置变量调解器用法详解
  • Smarty模板变量调节器用法分析
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端