这篇文章主要介绍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模板怎么用”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。