天天看点

Smarty 学习随记(5)

常量

SMARTY_DIR

是到smarty类目录的完全路径,必须以/结束。如果没有定义,将会自动决定路径.

SMARTY_CORE_DIR

是到smarty类core文件目录的完全路径,必须以/结束。如果没有定义,将会自动定义为smarty_dir路径下面的子目录.

变量

$template_dir

默认的模板目录名,默认为"./templates".

$compile_dir

默认的编译模板目录名,默认为"./templates_c"

$config_dir

默认的config文件目录名,默认为"./configs".

$plugins_dir

默认的插件目录名,默认为"plugins".

$debugging

debugging控制台。即一个显示变量的窗口.

$debug_tpl

debug窗口的模板

$debugging_ctrl

另一种控制debugging的方法。

$autoload_filters

对所有的模板使用过滤程序,这个变量是一个数组,其中关键字是过滤的类型,值是过滤的名字。

$compile_check

每次php执行将是否查看模板的内容是否改变。

$caching

决定是否缓存文件执行生成的文件。

$cache_dir

默认的模板缓存目录名,默认为"./cache".

$cache_lifetime

缓存的模板的过期时间,以秒计算. $caching值为-1则缓存的模板永不过期.

最后我放个我用的例子.大家仅做一个参考吧!!! <?php

error_reporting(7);

$TurnDot  =  substr(PHP_OS, 0, 3) == 'WIN'  ?  ";"  :  ":"  ;

$doc_root=$_SERVER['DOCUMENT_ROOT'];   //默认获取根路径

//$doc_root="E:/Myweb/an-cool.com/Web" ; //这里是指定路径

$lib_root=".".$TurnDot.$doc_root."/shopadmin".$TurnDot.$doc_root."/shopadmin/inc".$TurnDot.$doc_root."/".$TurnDot.$doc_root."/jpgraph/src/".$TurnDot.$doc_root."/Smarty/libs/".$TurnDot.$doc_root."/Smarty";

ini_set("include_path",$lib_root);

include("conf.global.php");  //这里是装载一个全局配置文件.

$Templates_root = $doc_root."/templates";  //定义摸版根目录

define("Templates",$Templates_root);

$templates  = isset($INFO['templates'])  ?  $INFO['templates']  :  'default'  ;

include_once('Smarty.class.php');

$tpl = new Smarty();                                                                   //建立smarty实例对象$tpl

$tpl->debugging = false;

$tpl->template_dir   = Templates."/".$templates  ;                             //设置模板目录

$tpl->compile_dir    = Templates."/".$templates  ."/templates_c";     //设置编译目录

$tpl->cache_dir      = $doc_root."/cache";                                //设置缓存目录

$tpl->cache_lifetime = 60 * 60 * 24;                                         //设置缓存时间

$tpl->cache_lifetime = 0;                                                          //设置缓存时间

$tpl->caching        = false;                                                        //这里是调试时设为false,发布时请使用true

$tpl->left_delimiter = '<{';

$tpl->right_delimiter= '}>';

$tpl->assign("template_dir",  $INFO['site_url']."/templates/".$templates ); //摸板路径

$tpl->assign("Site_Url",      $INFO['site_url']); //主站URL

$tpl->assign("LanguageIs",    $INFO['IS']); //语言包类型

$tpl->assign("HtmlTitle", $INFO['site_title']);     //TITLE内容

$tpl->assign("HtmlMeta",  $INFO['meta_keyword']);  //META内容

?>