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 ...
随机推荐
- Three-js 创建第一个3D场景
1.一个场景至少需要的三种类型组件 相机/决定哪些东西将在屏幕上渲染 光源/他们会对材质如何显示,以及生成阴影时材质如何使用产生影响 物体/他们是在相机透视图里主要的渲染队形:方块.球体等 ...
- python缓存装饰器,第二种方式(二)
来个简单的装饰器 def cached_method_result(fun): """方法的结果缓存装饰器""" @wraps(fun) d ...
- TIMEOUT HANDLING WITH HTTPCLIENT
https://www.thomaslevesque.com/2018/02/25/better-timeout-handling-with-httpclient/ The problem If yo ...
- Java虚拟机(三):Java 类的加载机制
1.什么是类的加载 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个java.lang.Class对象,用来封装类在方法区内的数据结构 ...
- Maven发布war包到Tomcat
一.修改Tomcat下配置文件tomcat-users.xml,然后启动 <role rolename="manager-gui"/> <role rolenam ...
- HttpClinet学习笔记
本文为学习httpClient学习过程中转载的文章,若涉及版权请留言. ----------------------------- 前言 超文本传输协议(HTTP)也许是当今互联网上使用的最重要的协议 ...
- Empire安装和试用
Empire2.0,powershell后渗透利器的安装和试用 https://www.restkhz.com/2017/05/empire-test/ 使用Empire“探索”Windows个人电脑 ...
- 查看一个dll是否是强命名[C#]
使用命令行工具SDK Command Prompt,键入:SN -T C:\*****.dll 就会显示出该dll具体的PublicKeyToken 数值. 如果该程序集没有强命名,则不会有Publi ...
- Splash images_enabled 属性
images_enabled属性用于设置加载页面时是否加载图片,如下,禁止之后,返回的页面截图就不会带有任何图片,加载速度也会快很多 function main(splash, args) splas ...
- 使用 Json 文件存储
将爬取到的数据以 Json 文件形式存储: import json import requests req = requests.get('http://www.baidu.com/') data = ...