首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 網頁程式設計 >> PHP 程式設計 >> PHP 綜合知識

Smarty 模板引擎安裝與配置快速入門

     編輯:PHP 綜合知識

Smarty 是 PHP 著名模板引擎,分離邏輯與顯示。本文記錄安裝步驟與基本配置。

安裝步驟

  1. 下載最新版:https://smarty.php.net/(當前 2.6.18)
  2. 解壓,將 libs 目錄重命名為 smarty,複製到網站目錄。
  3. 網站根目錄建立 templates(模板檔)與 templates_c(編譯快取)目錄。
  4. 給 templates_c 權限 755(可寫入)。

測試腳本 test.php

<?php
include_once('./Smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = "./templates";
$smarty->compile_dir = "./templates_c";
$smarty->left_delimiter = "{{";
$smarty->right_delimiter = "}}";
$smarty->assign('test','OK');
$smarty->display('test.html');
?>

模板 templates/test.html

<html><head></head><body>{{$test}}</body></html>

驗證

瀏覽 test.php,若顯示 OK 即安裝成功。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved