Missing template handler

From: Date: Thu, 06 Dec 2001 07:57:39 +0000
Subject: Missing template handler
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2160@lists.php.net to get a copy of this message
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

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