Parser 1.2
On the way to Calendar 1.2, which will use Parser to simplify the process of looping through days and make it, yet again, easier to update, I realized my templates were going to be bloody long and fairly ... static, so I had to update to Parser 1.2.
Parser 1.2 has yet another new feature: foreach loops. This allows you to--OK, here it gets complicated--define as a variable an array, call it $Loop, of associative arrays, say $Data, with tag => value data. Each $Data has the same array keys (theoretically) and different array values (theoretically). Then you put in the template something like:
{foreach:loop}
{name1} likes {name2}<br />
{endforeach:}This would print, provided the tags name1 and name2 were defined in each member of the variable "loop," one row of who-likes-who for each member of "loop." The structure is something like...And this would print something like, using that template above:$Loop = Array (
0 => Array (
"name1" => "Jessica",
"name2" => "Mark"
),
1 => Array (
"name1" => "Stewart",
"name2" => "Leslie"
),
);
$parser->addVariable("loop", $Loop);
Jessica likes Mark<br />
Stewart likes Leslie<br />
The potential here is obvious. It's a little tricky, yes, and not something one would want to do by hand, but it's not too hard to do it automatically, having another loop add arrays to the $Loop array before adding it as a variable. This is exactly what Calendar 1.2 will be doing.
All I wanted to do was streamline Calendar, and I ended up with a whole new control structure in Parser. Imagine that.
Labels: FrameWorks

0 Comments:
Post a Comment
<< Home