Smarty模板简单配置与使用方法示例
2019/6/30 16:38:22
本文主要是介绍Smarty模板简单配置与使用方法示例,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文实例讲述了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相关内容可查看本站专题:《smarty模板入门基础教程》、《PHP模板技术总结》、《PHP基于pdo操作数据库技巧总结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于smarty模板的PHP程序设计有所帮助。
这篇关于Smarty模板简单配置与使用方法示例的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28怎么把PHP程序打包?-icode9专业技术文章分享
- 2024-09-28怎么用Phar打包PHP程序?-icode9专业技术文章分享
- 2024-09-13手动在github上下载的mfpt包,怎么放到thinkphp5.0框架并正常使用-icode9专业技术文章分享
- 2024-09-05python的<class 'bytearray'>相当于php的哪个数据类型-icode9专业技术文章分享
- 2024-09-05php 导出银行卡号避免科学技术法的方法-icode9专业技术文章分享
- 2024-08-30什么样的php代码质量差被称为垃圾代码-icode9专业技术文章分享
- 2024-08-30用 PHP 调用拼多多的接口以获取订单状态消息的步骤方法和代码示例-icode9专业技术文章分享
- 2024-08-27phpunit单元测试框架的入门和使用方法介绍-icode9专业技术文章分享
- 2024-08-24PHP 中date("w") 周一是多少-icode9专业技术文章分享
- 2024-08-14thinkphp8.0获取域名或主机名方法-icode9专业技术文章分享