Re: Missing template handler

From: Date: Thu, 06 Dec 2001 14:25:54 +0000
Subject: Re: Missing template handler
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2162@lists.php.net to get a copy of this message
Smarty will have a default function/modifier handler, and will be coming along with plugins. It will probably work something like the following: {myfunc var1=foo var2=bar} * if myfunc is built-in or registered, use that function. * if the function 'smarty_func_myfunc' exists, use that function * if plugin file 'smarty_func_myfunc.php' exists in the plugins dir, include it and use that one. * all failed, call the default function handler. (by default will trigger error) Ivo Jansch wrote: > > Hello, > > I've hacked Smarty a bit so I can have a callback to my application when > a template does not exist. Maybe it's also useful for other people > using Smarty inside their application. It doesn't decrease performance > if you don't use the feature. You can use it to do some error reporting, > or, as in my case, use it to try to recreate the template on the fly > from some source. > > The missing_template_handler is a function you can define, which takes > the resource_name as parameter, and which should return true if Smarty > should retry to read the template. > > In the function _fetch_template_source, after the check if the file > resource is not available, I put this in the else statement: > > if (function_exists("missing_template_handler")) > { > if (missing_template_handler($resource_name)) > { > // file info is cached.. we must clean the cache. for the file > // is now different. > clearstatcache(); > > // try again > if (file_exists($resource_name) && is_readable($resource_name)) > { > $template_source = $this->_read_file($resource_name); > $template_timestamp = filemtime($resource_name); > } > else > { > // definitely fail. > $this->_trigger_error_msg("unable to read template resource > (still wrong after handler): \"$tpl_path\""); > return false; > } > } > else > { > // definitely fail. > $this->_trigger_error_msg("unable to read template resource > (handler failed): \"$tpl_path\""); > return false; > } > } > else > { > $this->_trigger_error_msg("unable to read template resource: > \"$tpl_path\""); > return false; > } > > Greetings, > Ivo > > -- > Ivo Jansch <ivo@ibuildings.nl> > ibuildings.nl BV - information technology > http://www.ibuildings.nl > > --- > You are currently subscribed to smarty as: monte@ispi.net > To unsubscribe send a blank email to $subst('Email.Unsub') > Visit Smarty's homepage at > http://www.phpinsider.com/php/code/Smarty/ -- Monte Ohrt <monte@ispi.net> http://www.ispi.net/

« previous php.smarty.general (#2162) next »