[PHP] php中使用smarty模板引擎 →→→→→进入此内容的聊天室

来自 , 2020-08-18, 写在 PHP, 查看 111 次.
URL http://www.code666.cn/view/421b3ac5
  1. <?php
  2. /*  定义服务器的绝对路径  */
  3. define('BASE_PATH',$_SERVER['DOCUMENT_ROOT']);
  4. /*  定义Smarty目录的绝对路径  */
  5. define('SMARTY_PATH','/04/Smarty/');
  6. /*  加载Smarty类库文件  */
  7. require BASE_PATH.SMARTY_PATH.'Smarty.class.php';
  8. /*  实例化一个Smarty对象  */
  9. $smarty = new Smarty;
  10. /*  定义各个目录的路径 */
  11. $smarty->template_dir = BASE_PATH.SMARTY_PATH.'templates/';
  12. $smarty->compile_dir = BASE_PATH.SMARTY_PATH.'templates_c/';
  13. $smarty->config_dir = BASE_PATH.SMARTY_PATH.'configs/';
  14. $smarty->cache_dir = BASE_PATH.SMARTY_PATH.'cache/';
  15. $smarty->left_delimiter = '{%';
  16. $smarty->right_delimiter = '%}';
  17. /*  使用Smarty赋值方法将一对儿名称/方法发送到模板中  */
  18. $smarty->assign('title','第一个Smarty程序');
  19. $smarty->assign('content','Hello,Welcome to study \'Smarty\'!');
  20. /*  显示模板  */
  21. $smarty->display('01/index.tpl');
  22. ?>
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. 01/index.tpl文件:
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>
  34. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  35. <title> {% $title %} </title>
  36. </head>
  37. <body>
  38. {% $content %}
  39. </body>
  40. </html>
  41.  

回复 "php中使用smarty模板引擎"

这儿你可以回复上面这条便签

captcha