Re: [SMARTY] Getting templates from strings

From: Date: Mon, 26 Aug 2002 10:31:02 +0000
Subject: Re: [SMARTY] Getting templates from strings
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-5826@lists.php.net to get a copy of this message
At 12:24 26/08/02 +0200, Geranium wrote:
I'm in a situation where I have a template already in a string and I want to pass it to Smarty to use in a fetch operation. However, to do that I have to pass in a named template - a template in a string does't have a name to give to smarty, so I can't seem to do it. I have started putting together a resource for smarty to accept a template in a string, but I'm concerned that this seems to be a remarkably complex route to do something so simple. Has anyone already written a resource to handle this?
Here's the function I use. It won't work for a fetch operation but you could use it in place of the fetch. Regards, Peter ==============
    function eval_string($var)
    {
        if (!isset($var)) {
            $this->trigger_error("eval: missing 'var' parameter");
            return;
        }
        if($var == '') {
                return;
        }
        $this->_compile_template("evaluated template", $var, $source);
        #print htmlspecialchars($var) . '<br>Source: ' . htmlspecialchars($source) . '<br>';
        ob_start();
                eval('?>' . $source);
        $evaled = ob_get_contents();
        ob_end_clean();
        return $evaled;
    }
=============== -- Narrow Gauge on the web - photos, directory and forums! http://www.narrow-gauge.co.uk Glenbranter - Scottish narrow gauge in 009 http://glenbranter.narrow-gauge.co.uk

« previous php.smarty.general (#5826) next »