1.MSmarty_class.php
<?php
/*@file:MSmarty_class.php
*
* @title:类,将使用smarty的前三个步聚封起
*
* @author:virhuiai
*
* @date:03-21-2013
*
* @modified:03-23-2013
*
*/
date_default_timezone_set('PRC');
//require_once('/usr/lib64/php/Smarty/Smarty.class.php');
require_once( 'Smarty/Smarty.class.php' );
class MSmarty extends Smarty{
function __construct(){
parent::__construct();
$this->setTemplateDir('/home/virhuiai/html/test/smarty/templates');
$this->setCompileDir('/home/virhuiai/html/test/smarty/templates_c');
$this->setConfigDir('/home/virhuiai/html/test/smarty/configs');
$this->setCacheDir('/home/virhuiai/html/test/smarty/cache');
$this->caching = Smarty::CACHING_LIFETIME_CURRENT;
$this->assign('app_name', 'Guest Book');
}
}
$smarty = new MSmarty();
//$smarty->right_delimiter='{{';
//$smarty->right_delimiter = '}}';
$right_delimiter='{{';
$right_delimiter = '}}';
//$smarty->assign('name','virhuiai');
//$smarty->display('setup.tpl');
?>
2.try_seciton.php
<?php
/*@file:try_seciton.php
*
* @title:类,将使用smarty的前三个步聚封起
*
* @author:virhuiai
*
* @date:03-21-2013
*
* @modified:03-23-2013
*
*/
include_once './class/MSmarty_class.php';
$people = array('tony','sweety','abc','four');
$smarty->assign('people',$people);
$smarty->display('try_section.tpl');
?>
3.try_seciton.tpl
{section name=n loop=$people}
name:{$people[n]}<br/>
{/section}