天天看点

在php中配置使用smarty模板引擎

Smarty是php的半官方模板引擎,从其主页位置就可以看出。使用简单,功能强大,本文就介绍一下smarty模板的安装和使用。

1) 现在模板的安装包,解压到根目录外的某个位置,比如解压到c:/phpLib/smarty

2)修改 php.ini文件,配置include_path。 如此文中的配置为:include_path="c:/phpLib/smarty/libs"

     注意,要把include_path前的分号去掉

3) 创建存放模板文件和配置文件的四个目录

       templates 存放模板文件的目录

      template_c 防止smarty编译的模板文件

      configs 放置专用的配置文件目录

       cache   在启用缓存的情况下,放置smarty缓存的所有文件

4)在php脚本使用smarty模板前,先制定上述四个目录的位置:

<?php

$smarty = new Smarty;

$smarty->template_dir = "templates";

$smarty->compile_dir = "template_c";

$smarty->config_dir = "configs";

$smarty->cache_dir = "cache";

?>

完成上述四个步骤后,就可以使用smarty模板了