Smarty模板簡單配置與使用方法示例
來源:易賢網(wǎng) 閱讀:566 次 日期:2016-08-19 14:54:13
溫馨提示:易賢網(wǎng)小編為您整理了“Smarty模板簡單配置與使用方法示例”,方便廣大網(wǎng)友查閱!

本文實例講述了Smarty模板簡單配置與使用方法。分享給大家供大家參考,具體如下:

在Smarty目錄中建立templates,templates_c,configs,cache目錄。以便Smarty進行編譯和緩存。

建立smarty_inc.php文件對smarty進行配置如下:

<?php

include_once("./smarty/Smarty.class.php"); //包含smarty類文件

$smarty = new Smarty(); //建立smarty實例對象$smarty

$smarty->caching=false; //開發(fā)是不建議開啟緩存

$smarty->template_dir="./templates"; //設置模板目錄

$smarty->compile_dir="./templates_c"; //設置編譯目錄

$smarty->cache_dir="./cache"; //緩存文件夾

$smarty->cache_lifetime=60;

$smarty->left_delimiter = "<{"; //左定界符

$smarty->right_delimiter = "}>"; //右定界符

?>

行測試,在根目錄下建立index.php文件:

<?php

include("smarty_inc.php");

$val= array("丁慶","董丹鳳","情侶");

$smarty->assign("name",$val);

$smarty->display("index.html");

?>

在templates下建立index.html模板:

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset="utf-8">

<title>測試頁面</title>

</head>

<body>

<{foreach from=$name item=x}>

數(shù)組內(nèi)容:<{$x}> <br/>

<{/foreach}>

</body>

</html>

好了,大功告成,就是這么簡單。

希望本文所述對大家基于smarty模板的PHP程序設計有所幫助。

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:Smarty模板簡單配置與使用方法示例
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)