Ho scaricato da un sito una "class template", in modo da poter dividere il codice php da quello html. Questa è la classe:

Codice PHP:
class sysTemplate
{
    var 
$template;
    var 
$_tpldata = array();

    function 
sysTemplate($ts=array(),$cache='d_cache.txt',$sec=3600,$tpl='tpl.html')
    {
        if(!
$this->template=$this->r($cache,$sec))
        {
            (@
file_exists($tpl))?$this->template=@file_get_contents($tpl):die('Attenzione: Il file '.$tpl.' non è presente');
            
$this->parserT($ts,$cache);
        }
    }

    function 
parserT($ts,$cache)
    {
        if(@
count($ts)>0)
        {
            foreach(
$ts as $t=>$d)
            {
                
$d=(@file_exists($d))?$this->getFile($d):$d;
                
$this->template=@str_replace('{'.$t.'}',$d,$this->template);
            }

            
$this->buildCache($cache,$this->template);
        }
        else
        {
            die(
'Attenzione: impossibile eseguire il replace dei tags.');
        }
    }

    function 
getFile($doc)
    {
        @
ob_start();
        include(
$doc);
        
$contenuto=@ob_get_contents();
        @
ob_end_clean();
        return 
$contenuto;
    }

    function 
buildCache($cache,$contenuto)
    {
        
$f=@fopen($cache,'w');
        @
fwrite($f,$contenuto);
        @
fclose($f);
    }

    function 
r($cache,$sec)
    {
        if(@
file_exists($cache)&&@filemtime($cache)>(@time()-$sec))
        {
            return @
file_get_contents($cache);
        }

        return 
false;
    }
   
    function 
show()
    {
        return 
$this->template;
    }

Funziona tutto benissimo, ma vorrei aggiungere una function. In pratica nella mia pagina alcune parti di html si trovano all'interno di alcuni If, ora... per richiamare il file html devo utilizzare questa riga:

Codice PHP:
$temp=&new sysTemplate($ts,'filecache.txt',0,'nomefile.htm'); 
ciò significa che dovrei dividere il codice html in più files e richiamare in ogni If il file html corrispondente.
Nella class template del forum phpbb, c'è una function che fa quello che vorrei io. Funziona così: si mettono, ad esempio, queste due righe:

Codice PHP:
 
all'inizio e alla fine dell'html che voglio mostrare solo effettuando l'if e poi richiamo la funzione in questo modo:

Codice PHP:
$template->assign_block_vars'register' , array()); 
Così facendo l'html tra i due tags appare solamente una volta effettuato l'if. Nel mio caso dovrei cambiare quella riga in:

Codice PHP:
$temp->assign_block_vars'register' , array()); 
ma non so come modificare la function per renderla funzionante.

Codice PHP:
    function assign_block_vars($blockname$vararray)
    {
        if (
strstr($blockname'.'))
        {
            
// Nested block.
            
$blocks explode('.'$blockname);
            
$blockcount sizeof($blocks) - 1;
            
$str '$this->_tpldata';
            for (
$i 0$i $blockcount$i++)
            {
                
$str .= '[\'' $blocks[$i] . '.\']';
                eval(
'$lastiteration = sizeof(' $str ') - 1;');
                
$str .= '[' $lastiteration ']';
            }
            
// Now we add the block that we're actually assigning to.
            // We're adding a new iteration to this block with the given
            // variable assignments.
            
$str .= '[\'' $blocks[$blockcount] . '.\'][] = $vararray;';

            
// Now we evaluate this assignment we've built up.
            
eval($str);
        }
        else
        {
            
// Top-level block.
            // Add a new iteration to this block with the variable assignments
            // we were given.
            
$this->_tpldata[$blockname '.'][] = $vararray;
        }

        return 
true;
    } 
Non è molto lunga, ma non so proprio come modificarla... sapreste aiutarmi?