TplBlock/test-TplBlock/test.php

47 lines
1.0 KiB
PHP
Raw Normal View History

2018-03-17 13:50:04 +01:00
<?php
include("../class.TplBlock.php");
$tpl = new TplBlock();
2018-03-19 11:56:15 +01:00
//simples vars
2018-03-17 13:50:04 +01:00
$tpl->add_vars(array(
"name" => "Gnieark",
"title" => "Monsieur",
"firstname" => "Grouik"
)
);
$primes = array(1,2,3,5,7,11);
2018-03-19 11:56:15 +01:00
// a sub bloc
2018-03-17 13:50:04 +01:00
foreach($primes as $prime){
$tplPrime = new TplBlock('primes');
$tplPrime->add_vars(array('number' => $prime));
$tpl->add_sub_block($tplPrime);
}
2018-03-19 11:56:15 +01:00
// test sub - sub blocs
for ($i = 2; $i < 121; $i++){
$tplNumber = new TplBlock('number');
$tplNumber->add_vars( array("value" => $i));
$index = 1;
$number = $i;
while ( $number > 1 && $index < count($primes)){
if($number % $primes[$index] == 0){
$number = $number / $primes[$index];
$tplDivisor = new TplBlock("divisor");
$tplDivisor->add_vars( array("value" => $primes[$index]));
$tplNumber->add_sub_block($tplDivisor);
}else{
$index++;
}
}
$tpl->add_sub_block($tplNumber);
}
2018-03-17 13:50:04 +01:00
2018-03-19 19:13:19 +01:00
echo $tpl->apply_tpl_file("sample.txt",true);