Default template handler function

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Next

Default template handler function

<?php
// put this function somewhere in your application

function make_template ($resource_type, $resource_name, &$template_source, &$template_timestamp, &$smarty_obj)
{
	if( $resource_type == 'file' ) {
		if ( ! is_readable ( $resource_name )) {
			// create the template file, return contents.
			$template_source = "This is a new template.";
			$template_timestamp = time();
			$smarty_obj->_write_file($resource_name,$template_source);
			return true;
		}
 } else {
		// not a file
		return false;
 }
}

// set the default handler
$smarty->default_template_handler_func = 'make_template';
?>

Prev 来源:PHP中文社区 Home Next
Templates from other sources Up Extending Smarty With Plugins