跳至内容
Python 俱乐部
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您的足迹:
php:smarty:simple-example
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== Smarty 简单例子 ====== 下面的例子是基于Smarty 2.6版本的,可以不适用与Smarty 3。 ===== Smarty 目录结构 ===== 创建以下三个目录结构: <code> smarty/ smarty_run/ templates/ </code> * smarty: smarty库文件 * smarty_run: smarty临时文件 * templates: .tpl模板文件 ===== php脚本设置 ===== <code php> require("smarty/libs/Smarty.class.php"); $smarty = new Smarty; $smarty->config_dir="smarty/libs/Config_File.class.php"; $smarty->caching=false; $smarty->cache_dir="smarty_run/cache/"; $smarty->template_dir="templates"; $smarty->compile_dir="smarty_run/templates_c/"; $smarty->left_delimiter = "{{"; $smarty->right_delimiter = "}}"; // ... // ... // pass variables to smarty $url = "http://www.pythonclub.org/"; $smarty->assign('title', $title); $smarty->assign('url', $url); $smarty->assign('post', $post); $smarty->assign('id', $id); $smarty->display('post.tpl'); </code> ===== tpl模板文件 ===== <code html> <!-- post content start --> <div class="content-body"> <!-- title --> <div class="custom-title text-left"><h2 class="title">{{$title}}</h2><p class="sub_title"><br></p></div> <!-- rich content area --> <div class="custom-richtext"> <font size="4"> {{ $post }} </font><hr> <div style="clear:both"></div> </div> <!-- post content end --> </code>
php/smarty/simple-example.txt
· 最后更改: 2014/05/26 05:02 (外部编辑)
页面工具
显示页面
修订记录
反向链接
回到顶部