Safely handle fatal missing plugin/function errors?
| From: | Cameron Perry | Date: | Mon, 09 Jul 2007 08:15:26 +0000 |
| Subject: | Safely handle fatal missing plugin/function errors? | ||
| References: | 1 | Groups: | php.smarty.dev |
| Request: | Send a blank email to php-smarty-dev+get-3045@lists.php.net to get a copy of this message | ||
Hi everyone,
Maybe I'm missing something somewhere, but is there any way to gracefully handle the fatal errors if a requested template function doesn't exist? For example, if {myfunc} is written into the template but function.myfunc.php doesn't exist there is a fatal error that kills the remainder of the page render. Is there any built-in functionality in Smarty (though I didn't find it doesn't mean it doesn't exist) that would allow the script to catch that error and treat it almost as if the {myfunc} function was never requested in the first place? I could see it being as simple as returning NULL for functions, or returning the text contained within the block function tags. If there's nothing like that in Smarty, is it something the dev team could/would consider implementing in a future release?
For me it matters because I'm writing an app that allows users/content editors to add small page plugins to content areas. At the moment I simply plan on using a wrapper function that safely handles the above problem, but is still not my ideal work-around.
For example (forgive any errors - this is just off the top of my head for demonstration purposes... and it's pretty late at night :-)
{* in the template *}
{callfunc name="weather"}
//---- function.callfun.php --
smarty_function_callfunc($params, &$smarty){
if(function_exists("smarty_function_".$params['name']) {
// call the function and continue
// return output to template
} else {
return NULL; //there would be an empty spot where that plugin was placed.
}
}
//---- function.weather.php --
smarty_function_weather($params, &$smarty){
//get local weather
//fetch template & return
}
Any input is appreciated!
Thanks,
Cameron