這篇文章主要介紹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; //開發是不建議開啟緩存
$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}>
數組內容:<{$x}> <br/>
<{/foreach}>
</body>
</html>以上是“Smarty模板怎么用”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。