笑談Smarty技術配置與應用

來源:互聯網
上載者:User
  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";直接使用可以了。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.