Re: Adding Loop / If support to a simple template engine

From: Date: Thu, 07 Apr 2005 04:50:26 +0000
Subject: Re: Adding Loop / If support to a simple template engine
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-212507@lists.php.net to get a copy of this message
Just make your template engine compile templates to "native" php code. i.e. write a parser which replaces {if $foo}{$var}{/if} with <?php if($foo) {?><?php echo $this->templateVars['var'];?><?php } ?> To check if the template must be recompiled, just compare filemtimes. The assign function could be look like this then: ===== function assign($varName, $value = '') { if(is_array($varName)) foreach($varName as $key => $val) $this->assign($key, $val); else $this->templateVars[$varName] = $value; } =====

« previous php.general (#212507) next »