ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` // 1引入smarty include 'libs/Smarty.class.php'; // 2.实例化Smarty $smarty = new Smarty; $smarty->template_dir = 'view'; // 3.分配变量 $smarty->assign('time', time()); $smarty->assign('str', 'Hello World'); $smarty->assign('level', '白金会员'); function demo() { return 'aaa'; } // 4.编译并输出模板 $smarty->display('4.html'); ``` ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <h3>{$time}</h3> <h3>{time()}</h3> <h3>{date('Y-m-d H:i:s')}</h3>//和下面的一样两种都可以 <h3>{$time|date_format:"%Y-%m-%d"}</h3> <h3>{$str|lower}</h3> <h3>自定义函数值:{demo()}</h3> {* default是默认值,如果$level有值,取其值,没有则取default的值 *} <!----> <h3>{$level|default:'游客'}</h3> </body> </html> ```