Page 1 of 1

Variables from Array in Template System

Posted: Thu Oct 02, 2008 2:44 pm
by mikelbring

Code: Select all

<? 
function fetch_template($template,$data = null){ 
 
    eval('?'.'>'.trim($template).'<'.'?'); 
     
} 
 
 
$templatequery = $mysql->query("SELECT * FROM ".DBPREFIX."templates ORDER by name ASC"); 
while ($templ = mysql_fetch_array($templatequery,MYSQL_ASSOC)) 
{ 
 
    $template[$templ['name']] = $templ['body']; 
 
} 
 
$data['title'] = "Site Name"; 
 
fetch_template("header",$data); 
?>
I saw this in a framework I was studying. How would I display the title in the header template with out echoing $data['title']. The framework did echo $title. How would I make all variables come from the $data array?

Re: Variables from Array in Template System

Posted: Thu Oct 02, 2008 3:28 pm
by mikelbring
I figured it out. I had to put extract($data) in the function.