2009-12-25, 11:11 AM
hey guys
I have read a lot of threads on this forum about how myBB parses it's templates, using the eval() function. Anyway, none of this threads give a clear answer to how it actually passes the vars from the global scope into the eval function scope.
Could you PLEASE explain me how it's done (with code if possible).
For my own scripts I've managed to do it this way (minified code):
And the template.html file could look like this for example:
This code has one problem: it can't evaluate class objects or array keys... meaning: {$class->object} or {$array['key']} will lead to errors if written in the template.
I have read a lot of threads on this forum about how myBB parses it's templates, using the eval() function. Anyway, none of this threads give a clear answer to how it actually passes the vars from the global scope into the eval function scope.
Could you PLEASE explain me how it's done (with code if possible).
For my own scripts I've managed to do it this way (minified code):
$some_var = 'simon';
$other_var = 2;
parse();
function parse(){
ob_start();
include('template.html');
$output = ob_get_contents();
ob_end_clean();
$output = preg_replace('#{\$(.*?)}#sie', 'globalize(\'$1\')', $output );
print($output);
}
function globalize($var){
global $$var;
return $$var;
}
And the template.html file could look like this for example:
Hi {$some_var}, you have {$other_var} unread private messages!
This code has one problem: it can't evaluate class objects or array keys... meaning: {$class->object} or {$array['key']} will lead to errors if written in the template.