|  |  |  | 
서브클래스를 사용한 환경설정예제입니다.
 
| directory |  
| 
|  | / |  
|  |  | web |  |  
| Template.class.php |  
| <?php include dirname(__file__).'/Template_.class.php';
 class Template extends Template_
 {
 var $compile_check =true;
 var $compile_dir   ='/web/site1_inc/compile';
 var $compile_ext   ='php';
 var $skin          ='skin1';
 var $template_dir  ='/web/site1/_global';
 var $prefilter     ='adjustPath';
 
 function Template($skin='')
 {
 if ($skin) $this->skin = $skin;
 }
 }
 ?>
 |  
| directory1/index.php |  
| <?php include '/web/site1_inc/Template.class.php';
 $tpl=new Template;
 $tpl->define(array(
 'menu'  =>'menu.tpl',
 'main'  =>'dir1/template1.tpl',
 'layout'=>'layout.tpl',
 ));
 ...
 $tpl->print_('layout');
 ?>
 |  
아래는 본 홈페이지에 사용된 템플릿서브클래스입니다. 실행파일들이 공통적으로 사용하는 템플릿변수,파일아이디를 할당하거나, 메서드를 추가해주면 작업 효율을 높일 수 있습니다.
 Template.class.php 
<?php
include dirname(__file__).'/Template_.class.php';
 class Template extends Template_
 {
 var $compile_check =false;
 var $compile_ext   ='php';
 var $skin          ='v1';
 var $notice        =false;
 var $path_digest   =false;
 
 var $prefilter     ='adjustPath';
 var $postfilter    ='removeTmpCode | arrangeSpace';
 var $permission    =0777;
 var $safe_mode     =false;
 var $auto_constant =false;
 
 var $caching       =true;
 var $cache_expire  =0;
 
 function Template()
 {
 $this->template_dir=$_SERVER['DOCUMENT_ROOT'].'/_global';
 $this->compile_dir =$_SERVER['DOCUMENT_ROOT'].'/../include/_compile';
 $this->cache_dir   =$_SERVER['DOCUMENT_ROOT'].'/../include/_cache';
 $this->define(array(
 'layout'=>'layout.htm',
 '!head' =>'layout.htm?head',
 'body'  =>'layout.htm?body',
 'menu'  =>'menu.htm',
 ));
 $this->assign('url', dirname($_SERVER['PHP_SELF']).'/');
 }
 function setMenu($page)
 {
 $this->assign('page', $page);
 $this->assign('menu', array(
 array('introduction', '/',        '머리말'),
 array('benchmark', '/benchmark/', '벤치마크'),
 array('tutorial1', '/tutorial1/', '설명서 1'),
 array('tutorial2', '/tutorial2/', '설명서 2'),
 array('tutorial3', '/tutorial3/', '설명서 3'),
 array('tutorial4', '/tutorial4/', '설명서 4'),
 array('tutorial5', '/tutorial5/', '설명서 5'),
 array('reference', '/reference/', '레퍼런스'),
 array('download',  '/download/' , '다운로드'),
 array('bbs',       '/bbs/',       '게시판'),
 ));
 }
 }
 ?>
  |  |