Log in

View Full Version : Better template eval'ing


filburt1
12-05-2002, 06:40 PM
function evaltemplate($templatename, $storagevar)
// evals $templatename and stores the output in $storagevar
{
$localcopy = gettemplate($templatename);
eval("\$$storagevar = \"$localcopy\";");
}


...and after that, I run:


evaltemplate("templatename", "contentsvariable");


Finally, I put $contentsvariable at the top of the header. The template templatename exists. However nothing shows up in the header. Why?

filburt1
12-05-2002, 06:44 PM
Okay, I added this to the beginning of the function:

eval("global \$$storagevar;");

...and it's loading the template. However variables in the template aren't getting parsed due to the same variable scope issue.

Is there some way to make a function always modify global variables instead of local ones while at the same time not having to type global $varname; for each one?

okrogius
12-05-2002, 07:00 PM
you can just do something like:


eval( generate_eval_code('template_name') );


Well maybe not as lengthy, but the idea is there.

filburt1
12-05-2002, 07:01 PM
Hmm, good point, although I'd prefer something function-based for simplicity.

I searched on php.net for a way to basically ignore variable scope in functions and make every variable global but didn't get anything working.