建议使用一个兼容性好的smary版本。
太新的版本往往对php的版本支持不好。
 
php推荐使用的模板是:smarty
 
其他模板:phplib
公司自己写的模板
 
如何配置我们的smarty?
1.解压后,把libs文件夹放在网站根目录下。
2.创建两个文件夹 templates(放模板文件) 和templates_c(放编译后的俄文件)

开始使用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

注意事项:
 
1.替换变量的标识符一般使用:<{}>
因为{}会和内联css和js发生冲突。
 
改动分隔符有两个方法:
   1直接该smarty源码。
   2 动态修改分隔符
          $smarty = new Smarty;
          $smarty ->left_delimiter="<{";
          $smarty ->right_delimiter="}>";
 
传统方法的弱点:
1、php脚本和html,css,js混合,界面不简洁、
2.编写php页面要求程序员同时会网页设计技术、
3,不利于项目分工协同开发。
 
smarty的用处:
1。把界面需要的数据获取到,然后分配给某个界面。

smarty模板的配置的更多相关文章

  1. php Smarty模板引擎配置与测试

    Smarty简介 smarty是一个使用PHP写出来的模板PHP模板引擎,它提供了逻辑与外在内容的分离,简单的讲,目的就是要使用PHP程序员同美工分离,使用的程序员改变程序的逻辑内容不会影响到美工的页 ...

  2. 如何配置Smarty模板

    <?php //首先包含Smarty类文件 include_once('Smarty/Smarty.class.php'); //实例化Smarty类文件 $smarty=new Smarty( ...

  3. smarty模板配置代码详细说明及如何注册自己的smarty函数

    下面为smarty模板的配置文件,smarty配置的详细说明以及如何注册自己所需要的smarty函数 config.inc.php <?php /** * Smarty 调用 * www.daf ...

  4. 第八十七天请假 PHP smarty模板配置以及简单的调用方式

    smarty模板的配置文件 <?php define("ROOT",str_replace("\\","/",dirname(__FI ...

  5. 12月15日smarty模板基本语法

    smarty基本语法: 1.注释:<{* this is a comment *}>,注意左右分隔符的写法,要和自己定义的一致. <{* I am a Smarty comment, ...

  6. smarty模板引擎

    1.    使用smarty 1.1 项目引入 // 3, 连接数据库,提取相关数据 $title = "Smarty模板引擎"; $content = "Smarty模 ...

  7. Smarty模板技术学习

    模板引擎技术:使得php代码和html代码分离的技术就称为"模板引擎技术" 自定义smarty模板技术实现 <?php //迷你smarty原理 class MiniSmar ...

  8. 第八十八天请假 PHP smarty模板 变量调节器,方法和块函数基本书写格式

    变量调节器 : 文件命名格式(modifier.名称.php)  前端调用方式<{变量|名称:参数:参数……}>可组合使用,用|隔开 <?php /* 命名格式 smarty_mod ...

  9. smarty模板中引用常量没效果

    在thinkphp框架中使用Thinkph的模板引擎,css,js等都没问题,配置为smarty模板引擎后没效果,如图 代码为,$Smarty的s是大写,此时页面不能引入常量,改为小写后正常了. &l ...

随机推荐

  1. 【RespberryPi】数码管

    http://blog.mangolovecarrot.net/2015/06/03/raspi-study0801/ 应该可以用两块74HC595来驱动显示8位数的数码管.

  2. Spring3+mybatis3在多数据源情况下找不到数据库驱动的问题

    解决问题的过程如下: 1.遇到问题和一般的解决方法和下面这个帖子的一样: http://www.oschina.net/question/188964_32305 2.我在按照1的做法配置了以后,依然 ...

  3. symfony获取POST数据

    $request = $this->getRequest(); $messageid = $this->strip_tags($request->get('messageid')); ...

  4. MyBatis 原码解析(version:3.2.7)

    mybatis-plus 实践及架构原理.pdf mybatis-plus思维导图 首先,我们看使用原生的JDBC来操作数据库的方式: // 1. 获取JDBC Connection Connecti ...

  5. 虚拟机安装linux系统无法上网的解决方法

    原文:https://www.jb51.net/article/118267.htm 周末闲来无事,用虚拟机安装了centos6.5系统,安装成功后发现不能连接网络,然后我就一脸蒙蔽了,无奈之下,只能 ...

  6. phonegap入门–2 Android phonegap工程建立

    一.环境要求: 需要安装Android ADT 二.支持Android相关设备列表: a)Android 2.1 (Deprecated May 2013) b)Android 2.2 c)Andro ...

  7. ios开发之--调整UISearchBar的输入框的背景颜色

    遍历UISearchBar的子视图,找到输入框坐在的view,添加背景颜色即可. 代码如下: UISearchBar *searchBar = [[UISearchBar alloc] initWit ...

  8. 架设SVN服务器

    服务器端:windows 2003 + subversion 下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folder ...

  9. windowsError错误码详解

    WindowsError的错误代码详解 0操作成功完成. 1功能错误. 2系统找不到指定的文件. 3系统找不到指定的路径. 4系统无法打开文件. 5拒绝访问. 6句柄无效. 7存储控制块被损坏. 8存 ...

  10. mysql存储过程中使用事务

    DROP PROCEDURE IF EXISTS test_sp1 CREATE PROCEDURE test_sp1( ) BEGIN ; ; START TRANSACTION; INSERT I ...