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 ...
随机推荐
- 【项目管理】Project使用
http://www.cnblogs.com/wangfupeng1988/p/3647166.html
- Git使用教程,从入门到上瘾
Git 是什么? Git 是一个分布式的代码管理容器,本地和远端都保有一份相同的代码. Git 仓库主要是由是三部分组成:本地代码,缓存区,提交历史,这几乎是所有操作的本质,但是为了文章更加简单易懂, ...
- 9 云计算系列之Cinder的安装与NFS作为cinder后端存储
preface 在前面我们知道了如何搭建Openstack的keystone,glance,nova,neutron,horizon这几个服务,然而在这几个服务中唯独缺少存储服务,那么下面我们就学习块 ...
- Linux/Centos下/lib64/libc.so.6: version `GLIBC_2.14' not found问题
Centos的某个版本下编译了一个可执行程序,复制到另外一个Centos环境下去执行,结果出现了以下错误: /lib64/libc.so.6: version `GLIBC_2.14' not fou ...
- 一些JavaScript基本函数
1.document.write(”");为 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览 ...
- JAVA简单内存泄露分析及解决
一.问题产生 项目采用Tomcat6.0为服务器,数据库为mysql5.1,数据库持久层为hibernate3.0,以springMVC3.0为框架,项目开发完成后,上线前夕进行稳定性拷机,测试 ...
- java序列化/反序列化之xstream、protobuf、protostuff 的比较与使用例子
目录 背景 测试 环境 工具 说明 结果 结论 xstream简单教程 准备 代码 protobuf简单教程 快速入门 下载.exe编译器 编写.proto文件 利用编译器编译.proto文件生成ja ...
- Hibernate_day02讲义_使用Hibernate完成CRM客户管理中查询所有客户的操作
- CentOS-6.4 安装 PHP Memcached 扩展
1.获取安装文件包 [root@phpdragon home]# wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmem ...
- Import VMware ESXi from VirtualBox
VirtualBox can export appliance VMs to OVF format. And you can import the ovf format to VMware ESXi, ...