Default tag handler
| From: | Ivo Jansch | Date: | Fri, 21 Sep 2001 08:50:38 +0000 |
| Subject: | Default tag handler | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1502@lists.php.net to get a copy of this message | ||
Hello,
I'm developing an application around Smarty, which requires a default tag handler. This means, that if a template tag doesn't exist, it should call some default function that handles non existant tags. (instead of just generating an error message)
To accomplish this, I modified Smarty.class.php. I added this line to the list of member vars:
var $default_handler = "";
And this to the _compile_template function:
$smarty_compiler->default_handler = $this->default_handler;
In Smarty_Compiler.class.php, in the _compile_tag function, I changed the default: branch of the switch to this:
if (isset($this->compiler_funcs[$tag_command])) {
return $this->_compile_compiler_tag($tag_command, $tag_args);} else if (isset($this->custom_funcs[$tag_command])) {
return $this->_compile_custom_tag($tag_command, $tag_args);} else if(isset($this->default_handler) &&
function_exists($this->default_handler)) {
$funcname = $this->default_handler;
return $funcname($tag_command, $tag_args, $this);
} else {
$this->_syntax_error("unknown tag - '$tag_command'", E_USER_WARNING);
return;
}
Andrei and Monte, it would be nice if you could put this in the next release, I'm sure other people could benefit from this modification too.
--
Ivo Jansch <ivo@ibuildings.nl>
ibuildings.nl BV - information technology
http://www.ibuildings.nl