首页 > 语言 > PHP > 正文

Smarty模板简单配置与使用方法示例

2024-05-04 23:46:38
字体:
来源:转载
供稿:网友
这篇文章主要介绍了Smarty模板简单配置与使用方法,涉及Smarty模板的基本配置与缓存文件的相关使用技巧,需要的朋友可以参考下
 

本文实例讲述了Smarty模板简单配置与使用方法。分享给大家供大家参考,具体如下:

在Smarty目录中建立templates,templates_c,configs,cache目录。以便Smarty进行编译和缓存。

建立smarty_inc.php文件对smarty进行配置如下:

<?phpinclude_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>

好了,大功告成,就是这么简单。



注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选