smarty模板的配置
开始使用smarty
1.写一个模板文件(tpl),通常放在templates
2.在php文件中引入smarty的核心文件,并创建smarty对象:
//创建smarty对象
require_once './libs/Smarty.class.php';
3 $smarty = new Smarty;//建立smarty实例对象$smarty
把数据分配给smarty对象,给tpl文件分配要显示的结果集合。对象,数组。
//把$res分配到smarty对象
$smarty->assign("myArr",$arr);
//指定用哪个模版显示
$smarty->display("empList2.tpl");
初始化其他参数(这些初始化应该放在display函数上面)
$smarty -> caching = false;//是否使用缓存
$smarty -> template_dir = "./templates";//设置模板目录
$smarty -> compile_dir = "./templates_c";//设置编译目录
$smarty -> cache_dir = "./smarty_cache";//缓存文件夹
//修改左右边界符号
$smarty -> left_delimiter="<{";
$smarty -> right_delimiter="}>";
完整的代码应该是:
<?php
//创建smarty对象
require_once './libs/Smarty.class.php';
$smarty = new Smarty;//建立smarty实例对象$smarty
$smarty -> caching = false;//是否使用缓存
$smarty -> template_dir = "./templates";//设置模板目录
$smarty -> compile_dir = "./templates_c";//设置编译目录
$smarty -> cache_dir = "./smarty_cache";//缓存文件夹
//修改左右边界符号
$smarty -> left_delimiter="<{";
$smarty -> right_delimiter="}>";
$smarty -> assign("var1","hello world");//
$smarty -> display("hello.tpl");//
?>
3.一般在控制器中用。创建一个smarty对象。require_once
smarty模板的配置的更多相关文章
- php Smarty模板引擎配置与测试
Smarty简介 smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页 ...
- 如何配置Smarty模板
<?php //首先包含Smarty类文件 include_once('Smarty/Smarty.class.php'); //实例化Smarty类文件 $smarty=new Smarty( ...
- smarty模板配置代码详细说明及如何注册自己的smarty函数
下面为smarty模板的配置文件,smarty配置的详细说明以及如何注册自己所需要的smarty函数 config.inc.php <?php /** * Smarty 调用 * www.daf ...
- 第八十七天请假 PHP smarty模板配置以及简单的调用方式
smarty模板的配置文件 <?php define("ROOT",str_replace("\\","/",dirname(__FI ...
- 12月15日smarty模板基本语法
smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...
- smarty模板引擎
1. 使用smarty 1.1 项目引入 // 3, 连接数据库,提取相关数据 $title = "Smarty模板引擎"; $content = "Smarty模 ...
- Smarty模板技术学习
模板引擎技术:使得php代码和html代码分离的技术就称为"模板引擎技术" 自定义smarty模板技术实现 <?php //迷你smarty原理 class MiniSmar ...
- 第八十八天请假 PHP smarty模板 变量调节器,方法和块函数基本书写格式
变量调节器 : 文件命名格式(modifier.名称.php) 前端调用方式<{变量|名称:参数:参数……}>可组合使用,用|隔开 <?php /* 命名格式 smarty_mod ...
- smarty模板中引用常量没效果
在thinkphp框架中使用Thinkph的模板引擎,css,js等都没问题,配置为smarty模板引擎后没效果,如图 代码为,$Smarty的s是大写,此时页面不能引入常量,改为小写后正常了. &l ...
随机推荐
- ubuntu 的chmod 和 chown
1.chown改文件或目录的所有者和群组权限 格式 chown [OPTION]... [OWNER][:[GROUP]] FILE... 参数: -R 递归操作当前目录下的所有目录和文件: -h 更 ...
- xml文件加密上传和sftp下载解密基本思路
AES对称加密效率高,对大文件加密适合.RSA非对称加密效率低,更安全,对小文件加密适合. 整理 11:12 2016/8/4 加密:1.xml xml.md5摘要 2.(xml)aes加密 (xml ...
- Cannot retrieve the latest commit at this time.
此时无法检索最新提交. GitHub页面上提示: Cannot retrieve the latest commit at this time. 还没更新的意思,等他更新就好了. 更新后:
- 一个基于jquery的智能提示控件intellSeach.js
一.需求 我们经常会遇到[站内搜索]的需求,为了提高用户体验,我们希望能做到像百度那样的即时智能提示.例如:某公司人事管理系统,想搜索李XX,只要输入“李”,系统自然会提示一些姓李的员工,这样方便用户 ...
- 10 -- 深入使用Spring -- 5... 实现任务的自动调度
10.5 实现任务的自动调度 10.5.1 使用Quartz 10.5.2 在Spring中使用Quartz
- Quatz入门
Demo SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory(); Scheduler sched = sched ...
- vs2012修复问题
多装了一个.net framework4.5.1结果vs不能拥,借用了下面这个工具将vs2012从注册表中删除了 就能重装了 http://www.auslogics.com/en/software/ ...
- MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes
今天在用Navicat导入SQL文件时报错:MySql 错误 Err [Imp] 1153 - Got a packet bigger than 'max_allowed_packet' bytes ...
- MongoDB聚合管道
通过上一篇文章中,认识了MongoDB中四个聚合操作,提供基本功能的count.distinct和group,还有可以提供强大功能的mapReduce. 在MongoDB的2.2版本以后,聚合框架中多 ...
- 安装RVDS2.2
本人经过一晚上的折腾,已经将rvds2.2成功部署在为AMD平台的CPU上面,除了些许小BUG外,编译程序无任何错误,可成功将产上的AXF文件通过Jlink烧制到开发板上. 感谢cdly7475为我们 ...