-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
150 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>TemplateObject – recursion TEST</title> | ||
</head> | ||
<body> | ||
<p>Refresh page to see different results</p> | ||
<hr> | ||
|
||
<ul> | ||
<!-- BEGIN block --> | ||
<li> | ||
Recursion level {{LEVEL}} | ||
<ul> | ||
<!-- RECURSION block --> | ||
</ul> | ||
</li> | ||
<!-- END block --> | ||
</ul> | ||
|
||
<hr> | ||
|
||
<!-- BEGIN block2 --> | ||
[block-2] | ||
<!-- RECURSION block2 --> | ||
<!-- END block2 --> | ||
|
||
<hr> | ||
|
||
<!-- BEGIN block3 --> | ||
[block-3, level {{LEVEL}}] | ||
<!-- RECURSION block3 --> | ||
<!-- END block3 --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
require('../TemplateObject.php'); | ||
$to = TemplateObject::loadTemplate('recursion.html'); | ||
|
||
define('MAX_LEVEL', 5); | ||
recursion($to); | ||
|
||
$to->setBlock('block2')->setBlock('block2')->setBlock('block2'); | ||
|
||
$a = array( | ||
'block3' => array( | ||
'LEVEL' => 1, | ||
'block3' => array( | ||
'LEVEL' => 2, | ||
'block3' => array( | ||
'LEVEL' => 3, | ||
), | ||
), | ||
), | ||
); | ||
$to->setVarArray($a); | ||
|
||
$to->showOutput(); | ||
|
||
function recursion(&$tmpl, $level = 0) | ||
{ | ||
$rows = rand(1, 3); | ||
for($i=1; $i<=$rows; $i++) { | ||
$b = $tmpl->setBlock('block'); | ||
$b->setVariable('LEVEL', $level); | ||
$go_deep = !$level || rand(0, 1); | ||
if($go_deep && $level < MAX_LEVEL) recursion($b, ++$level); | ||
} | ||
} |