Re: [SMARTY] default_template_handler_func

From: Date: Sat, 05 Apr 2003 09:51:05 +0000
Subject: Re: [SMARTY] default_template_handler_func
References: 1 2 3  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-9115@lists.php.net to get a copy of this message
On Sat, Apr 05, 2003 at 08:14:59AM +0000, messju mohr wrote: > On Sat, Apr 05, 2003 at 08:07:41AM +0000, messju mohr wrote: > > On Thu, Apr 03, 2003 at 06:52:52PM -0800, AaronJ wrote: > > > Hello, > > > > > > I have been ignoring this for a long time, but since maybe someone has a > > > solution, or we can create one: > > > > > > I run multiple sites off one smarty script. Smarty is located outside of the > > > web dirs and included when run. (/usr/local/smarty) > > > > > > ie.. > > > Server: > > > > > > /usr/local/smarty/ > > > /plugins > > > /templates > > > > > > Clients: > > > > > > /var/www/html/site1 > > > index.php calls smarty > > > /templates > > > /template_c > > > /config > > > /var/www/html/site2 > > > index.php calls smarty etc... > > > > > > And my functionality is that each client can have their own templates, but > > > if a template is called, and it doesn't exist in their own directory I then > > > I will use on from my 'server' side: > > > > > > Define ("default_template_dir", "/usr/local/smarty/templates/"); > > > $smarty->default_template_handler_func = "displayTemplate"; > > > > > > function displayTemplate($resource_type, $resource_name, $template_source, > > > $template_timestamp, $this) { > > > $tpl = default_template_dir .$resource_name; > > > $this->display($tpl,cache_id); > > > } > > > > > > This works.. but I get : > > > Warning: Smarty error: unable to read template resource: > > > "breadcrumbpath.tpl" in /usr/local/smarty/Smarty.class.php on line 1040 > > > > displayTemplate() should return true to indicate success. smarty won't emit > > the warning then. > > > > additionally: you should set $template_source and $template_timestamp > > instead of displaying the template yourself: > > > > (not tested: ) > > > function displayTemplate($resource_type, $resource_name, &$template_source, > > &$template_timestamp, $this) { > > $tpl = default_template_dir .$resource_name; > > if (file_exists($tpl)) { // to prevent endless loop > > $template_source = $this->fetch($tpl,cache_id); > > $template_timestamp = filemtime($tpl); > > return true; > > } > > > > return false; // even default-template not found. > > } > > messju: this is nonsense. the template would be compiled twice with > this approach. this is not intended. > > okay. sorry it's still early saturday in my timezone. i meant > something like: > > (also not tested , but better :) > function displayTemplate($resource_type, $resource_name, &$template_source, > &$template_timestamp, $this) { > $tpl = default_template_dir .$resource_name; > if ($fp=fopen($$tpl)) { > $template_source = fread($fp, filesize($tpl)) > $template_timestamp = filemtime($tpl); > fclose($fp); > return true; > } > return false; // even default-template not found. > } > > > AFAIR the default_template_handler should just provide the template > source. the compilation/execution of the template is done by smarty > then. it seems i love to reply myself today. so i don't want to leave you alone, with that buggy example. this one is tested and works good for me (maybe i encounter the need for a fall-back template-dir myself soon :) function tpl_handler($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty) { $tpl = $smarty->default_template_dir . $resource_name; if ($fp=fopen($tpl, 'r')) { $template_source = fread($fp, filesize($tpl)); $template_timestamp = filemtime($tpl); fclose($fp); return true; } // no return means null, means false, means error } (for the records: no, i didn't invest all the time between my previous post and this one into your problem. i had breakfast and repaired my bicycle additionaly :-) have fun messju > greetings > messju > > > HTH > > messju > > > > > For every templates included like this... now it seems wrong... but I forged > > > ahead and have altered every new release of Smarty.class.php to fix this: > > > By changing QUIET=TRUE in the smarty.class.php, function > > > _fetch_template_info the warnings go away. > > > > > > However, this all seems very wrong.. so can someone let me know what I am > > > doing wrong, or can we change smarty so that I can leave smarty.class alone? > > > > > > Thanks, > > > > > > Aaron Judd

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