smarty的入门及简单的编码

smarty建立配置文件、显示文件后即可,配置文件显示文件分开来,使美工跟开发工作能完美分开

配置页面代码:index.php

  1. <?php
  2. @header("Content-type: text/html; charset=UTF-8");
  3. require '../libs/Smarty.class.php';
  4. $my=new Smarty;
  5. $my->template_dir ='templates/';
  6. $my->compile_dir ='templates_c/';
  7. $my->config_dir ='configs/';
  8. $my->cache_dir ='cache/';
  9. $my->assign('content','welcome to arrival');
  10. $my->assign('mylife',array("生活","吃饭","梦想","凉风"));
  11. $my->display('kk.html'); //显示smarty目录下的kk.html
  12. ?>

kk.html

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>无标题文档</title>
  6. </head>
  7. <body>
  8. {$content}
  9. {section name=truelife loop=$mylife}
  10. {$mylife[truelife]}
  11. {/section}
  12. </body>
  13. </html>