<?php include '../header.inc.php'; $tpln = new Tpln_Engine(); $tpln->open('template.html'); $families = [['lastname' => 'Sters', 'childrens' => [['lastname' => "Sters", 'firstname' => 'Amanda'], ['lastname' => "Mopius", 'firstname' => 'Billy'], ['lastname' => "Sters", 'firstname' => 'Luc jr']]], ['lastname' => 'Berguson', 'childrens' => []], ['lastname' => 'Alfonso', 'childrens' => [['lastname' => "Vitali", 'firstname' => 'Antonio'], ['lastname' => "Bougloni", 'firstname' => 'Marcelo']]]]; foreach ($families as $family) { $tpln->parse('family.lastname', $family['lastname'], '|strtoupper'); $tpln->parse('family.children_count', count($family['childrens'])); if (!count($family['childrens'])) { $tpln->eraseBloc('family.children'); $tpln->loop('family.children'); } else { foreach ($family['childrens'] as $children) { $tpln->parse('family.children.firstname', $children['firstname']); $tpln->parse('family.children.lastname', $children['lastname']); $tpln->loop('family.children'); } } $tpln->loop('family'); } echo $tpln->render();
<?php include '../header.inc.php'; $tpln = new Tpln_Engine(); $tpln->open('template.html'); // bloc 1 $index_1 = rand(1, 3); for ($i = 0; $i < $index_1; $i++) { $tpln->parse('level_1.text', $i + 1 . " / {$index_1}"); // bloc 2 $index_2 = rand(1, 3); for ($j = 0; $j < $index_2; $j++) { $tpln->parse('level_1.level_2.text', $j + 1 . " / {$index_2}"); // bloc 3 $index_3 = rand(1, 3); for ($k = 0; $k < $index_3; $k++) { $tpln->parse('level_1.level_2.level_3.text', $k + 1 . " / {$index_3}"); $tpln->loop('level_1.level_2.level_3'); } $tpln->loop('level_1.level_2'); } $tpln->loop('level_1'); } echo $tpln->render();
<?php include '../header.inc.php'; $tpln = new Tpln_Engine(); $tpln->open('template.html'); $users = [['firstname' => "John", 'lastname' => "Doe"], ['firstname' => "Johnny", 'lastname' => "Depp"], ['firstname' => "Sarah", 'lastname' => "Connor"], ['firstname' => "Arnorld", 'lastname' => "Swcharzenegger"]]; foreach ($users as $user) { $tpln->parse('users.firstname', $user['firstname']); $tpln->parse('users.lastname', $user['lastname']); $tpln->loop('users'); } // or you can use @foreach syntax in template see example echo $tpln->render();