Get Smarty


Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Shop for 2018 World Cup Football Boots Online sale at

Browse best 2018 world cup soccer cleats and shoes from





该设置一般在当模板是文件资源的时候起作用。 当找不到资源自身的时候,该设置不会调用,而是会抛出SmartyException异常。

Example 13.5. $default_template_handler_func


$smarty = new Smarty();
$smarty->default_template_handler_func = 'my_default_template_handler_func';

 * 默认模板处理函数
 * 当Smarty的文件资源无法载入需要的文件时调用。
 * @param string   $type     资源类型 (如:"file", "string", "eval", "resource")
 * @param string   $name     资源名称 (如:"foo/bar.tpl")
 * @param string  &$content  模板的内容
 * @param integer &$modified 模板修改时间
 * @param Smarty   $smarty   Smarty实例
 * @return string|boolean   返回文件路径或布尔值,
 * 布尔值true表示$content 和 $modified已经赋值,
 * 布尔值false表示没有默认模板可供载入。
function my_default_template_handler_func($type, $name, &$content, &$modified, Smarty $smarty) {
    if (false) {
        // 返回文件路径
        return "/tmp/some/foobar.tpl";
    } elseif (false) {
        // 直接返回模板内容
        $content = "the template source";
        $modified = time();
        return true;
    } else {
        // 告诉Smarty无法找到模板
        return false;



No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 12 plus 14? (Are you human?)