首頁  >  文章  >  後端開發  >  笑談Smarty技術配置與應用

笑談Smarty技術配置與應用

WBOY
WBOY原創
2016-07-25 09:05:52907瀏覽
  1. <{$title}>
  2. <{$content}>
复制代码

保存在 templates 目录中。

5、新建文件模板配置文件: config.php

  1. include "../libs/Smarty.class.php";
  2. $NowPathArray=explode("test",str_replace("\","/",dirname(__FILE__))) ;
  3. @define("root_path", $NowPathArray[0]);
  4. @define('__SITE_ROOT', root_path."test");
  5. $tpl = new Smarty();
  6. $tpl->template_dir = __SITE_ROOT . "/templates/";
  7. $tpl->compile_dir = __SITE_ROOT . "/templates_c/";
  8. $tpl->config_dir = __SITE_ROOT . "/configs/";
  9. $tpl->cache_dir = __SITE_ROOT . "/cache/";
  10. $tpl->left_delimiter = '<{';
  11. $tpl->right_delimiter = '}>';
  12. ?>
复制代码

保存在主目录 test中。

6、在test中新建文件test.php

  1. require "config.php";
  2. $tpl->assign("title", "测试成功了,这是标题");
  3. $tpl->assign("content", "这是内容");
  4. $tpl->display('test.htm');
  5. ?>
复制代码

7:在浏览器测试test.php显示为:

这是内容

恭喜,配置成功.否则,失败,再检查是不是按照我说的来的.

Tips1 :为了能在网站全局使用Smarty技术,我们可以修改PHP.inc里面的

; Windows: "path1;path2" include_path = ".;c:phpincludes"

改为: -------------------> ; Windows: "path1;path2" include_path = ".;c:phpincludes;d:webwebphplibs" 使用模板的时候,像前面一样的方式使用,不要 include "../libs/Smarty.class.php"; 直接使用可以了。



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn