Дать Smarty шаблон в виде строки

Pearmaster

Guest
Дать Smarty шаблон в виде строки

Как можно передать смарти шаблон в виде строки? Можно конечно временно записывать файл, указывать смарти на него и потом удалять этот файл, но это как то некрасиво. Есть ли способ решить проблему?
 

Gorath

Новичок
Например так:
PHP:
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File:     resource.fromvar.php
* Type:     resource
* Name:     fromvar
* Purpose:  Fetches templates from a global variable
* Author:   Altex
* -------------------------------------------------------------
*/
function smarty_resource_fromvar_source($tpl_name, &$tpl_source, &$smarty)
{
    // do database call here to fetch your template,
    // populating $tpl_source
    if (isset($GLOBALS[$tpl_name])) {
        $tpl_source = $GLOBALS[$tpl_name];
        return true;
    } else {
        return false;
    }
}

function smarty_resource_fromvar_timestamp($tpl_name, &$tpl_timestamp, &$smarty)
{
    // do database call here to populate $tpl_timestamp.
    if (true) {
        $tpl_timestamp = 99999999999999;
        return true;
    } else {
        return false;
    }
}

function smarty_resource_fromvar_secure($tpl_name, &$smarty)
{
    // assume all templates are secure
    return true;
}

function smarty_resource_fromvar_trusted($tpl_name, &$smarty)
{
    // not used for templates
}
?>
переменная должна быть глобальной
 
10 лет тут не причём. Дело в том, что на запрос "smarty шаблон из строки" эта страница первая на русском (так, вторая) в гугле, а ответа нет. Вот буду ещё через 10 лет искать, как это сделать, и найду.
 
Сверху