parse if's in my template engine?

Status
Not open for further replies.

timtamboy63

Active Member
885
2009
0
0
Does anyone have any good ways of parsing these if statements? Something like:
[if condition=this] blah blah
[/if]

Once that's done and i've coded the caching, my template engine will be done :D

But yeah, that's the only thing that's really annoying me atm, I can probably detect them with regex, but i don't really know how i'd parse them?
 
6 comments
you have to set up an array of comparison operators

array(
'=',
'>',
'<',
...
);


then you have to match the IF block like si

preg_match_all('/if\((?p<expr>)\{(?P<action>)\}/s');

then for the matched expr, you have to spit it up into () brackes so yo ucan do

[if 1 = 2 && 2 = 7 && ({var} == 88)]

[/endif]

[if <expr>]
<action>
[/[end|else]if] //Match this.
 
yah, that bit isn't all that hard, what i can't work out how to do is get it to parse the if's
i can't replace it with php as it prints out the php in the source rather than executing it.
 
What do you mean by parse, if you matched them with regex you know what values have to be checked, if you check them and its logically true then parse and execute whats within the IF block.
 
Yea Hyperz, i think he means how to convert like so

Code:
[set MyVariable=3]
[if %MyVariable > 3]
   [require_once 'test.tpl']
[/if]

into

PHP:
$MyVariable = 3;
if($MyVariable > 3):
   $engine->require_once('test.tpl')
endif;

so he has a php version.
 
Yeah exactly,, that cache thing that hyperz said would probably work right? Im just not too sure how i'd get it to work. Hm i'll take a look at it anyway
 
Status
Not open for further replies.
Back
Top