smarty学习3

来源:互联网 发布:免费股票交易软件 编辑:程序博客网 时间:2024/05/29 04:18

smarty变量调节器与编译,引入文件

<?php //03.phpheader('content-type:text/html;charset=utf-8');// 变量调节器//编译require 'smarty/Smarty.class.php';$smarty = new  Smarty();$smarty->template_dir='dir/';// $smarty->force_compile=true;//强制编译$smarty->caching=true;//设置缓存$smarty->cache_lifetime=3;//缓存周期3秒//如果没有开启缓存if (!$smarty->isCached('03.tpl')) {    $smarty->assign('k', 'abcEfg');}echo $smarty->fetch('03.tpl');//fetch输出模板?>
//03.tpl    {* 文件引入 *}    {include file="header.html"}    {$k|upper}    {* 变量调节器 *}    {$smarty.now|date_format:'%H:%M:%S'}    {* 文件引入 *}    {include file="footer.html"}
//header.html<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title></head><body>    我是头部
//footer.html哈哈,我是尾部</body></html>
0 0
原创粉丝点击