Categories > TinyButStrong general >

Dynamic Loadtemplate from a variable

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Tobi
Date: 2006-11-28
Time: 17:33

Dynamic Loadtemplate from a variable

I want to load my template not from a file but use a variable.

I´ve tried with modrewrite but i saw in the sourcecode, that a real file is needed.

Is there a plugin, not to load a file but a variable? Or how do i have to change the code?
By: Skrol29
Date: 2006-11-28
Time: 17:40

Re: Dynamic Loadtemplate from a variable

Hi Tobi,

You can do it simply like this:
$TBS->Source = $my_var;
$TBS->MergeField('onload'); // process [onload] tags.
By: Tobi
Date: 2006-12-05
Time: 02:43

Re: Dynamic Loadtemplate from a variable

Is it very stupid to change the tbs code like this, that if the content of loadtempalte starts with loadvar, than parse the variable as template?
By: Skrol29
Date: 2006-12-05
Time: 10:12

Re: Dynamic Loadtemplate from a variable

I was studying for such a feature, but I haven't found a way to do it that can be very clean.
The solution you're proposing will make a code like this:
$TBS->LoadTemplate('loadvar'.$mytemplate);

This is working, but quite strange.
Maybe we should had an extra argument to this method. Something like this:
$TBS->LoadTemplate($mytemplate,$charset,true);
By: Tobi
Date: 2006-12-06
Time: 01:49

Re: Dynamic Loadtemplate from a variable

Year, that would be really good. For now, this is my solution:

A changing of this function:
function tbs_Misc_GetFile(&$Txt,&$File,$LastFile='') {

// Load the content of a file into the text variable.

    $Txt = '';
/*new begin */
    if (substr($File,0,8)=='vartpl--') {
        $len = strlen($File);
        $Txt = substr($File,8,$len);
        return true;
    } else {

/*new end */
        $fd = @fopen($File, 'r'); // 'rb' if binary for some OS

        if ($fd===false) {

            if ($LastFile==='') return false;

            $File2 = dirname($LastFile).'/'.$File;

            $fd = @fopen($File2, 'r');

            if ($fd===false) return false;

            $File = $File2;

        }

        if ($fd===false) return false;

        $fs = @filesize($File); // return False for an URL

        if ($fs===false) {

            while (!feof($fd)) $Txt .= fread($fd,4096);

        } else {

            if ($fs>0) $Txt = fread($fd,$fs);

        }

        fclose($fd);

        return true;
/*new begin */
    }

/*new end */
}