示例#1
0
文件: index.php 项目: h2lsoft/tpln
<?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();
示例#2
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$models = array('Fiat 500', 'Mercedes class A', '');
$model = $models[rand(0, 2)];
$tpln->open('template.html');
echo $tpln->render();
示例#3
0
文件: index.php 项目: h2lsoft/tpln
<?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();
示例#4
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$tpln->open('template.html');
$tpln->parse('first_name', "John");
$tpln->parse('last_name', "doe", '|strtoupper');
echo $tpln->render();
示例#5
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$tpln->open('template.html');
$tpln->parse('var', "parsing from included");
echo $tpln->render();
示例#6
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$families = [['lastname' => 'Sters', 'children' => [['lastname' => "Sters", 'firstname' => 'Amanda'], ['lastname' => "Mopius", 'firstname' => 'Billy'], ['lastname' => "Sters", 'firstname' => 'Luc jr']]], ['lastname' => 'Berguson', 'children' => []], ['lastname' => 'Alfonso', 'children' => [['lastname' => "Vitali", 'firstname' => 'Antonio'], ['lastname' => "Bougloni", 'firstname' => 'Marcelo']]]];
$tpln->open('template.html');
$tpln->parseArray('family', $families);
echo $tpln->render();
示例#7
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$tpln->open('template.html');
$output = $tpln->render();
if (!isset($_GET['ajax'])) {
    die($output);
} else {
    $bloc = $tpln->getAjaxBloc("content", $output);
    die($bloc);
}
示例#8
0
文件: index.php 项目: h2lsoft/tpln
<?php

include '../header.inc.php';
$tpln = new Tpln_Engine();
$tpln->open('template.html');
// form custom
$tpln->formSetLang('en');
$tpln->formSetName('my_form');
$tpln->formSetInputName('ZipCode', 'Zip code');
$tpln->formSetInputName('CreditCard', 'Credit card');
// input form init example (use record from database for example)
$record = array('Gender' => 'MALE', 'Name' => 'John', 'Colors' => array('Green', 'Blue'));
$tpln->formInit($record);
// form rules
$tpln->required('Gender')->inList('', array('MALE', 'FEMALE'));
$tpln->required('Name')->alpha()->min('', 5)->max('', 15);
$tpln->required('Birthdate')->date('', 'd/m/Y');
$tpln->required('Email')->email();
$tpln->required('Country');
$tpln->required('Fruits[]');
$tpln->required('Colors[]')->inList('', array('Red', 'Green', 'Blue'));
# multiple
$tpln->alphaNumeric('Password', array('-', '_'));
$tpln->digit('ZipCode')->charLength('', 5, 5);
$tpln->required('CreditCard')->mask('', '9999-99-99 AAA 9999');
$tpln->fileControl('File', false, '10 ko', 'txt', 'text/plain');
// image jpg <= 500 x 500 and 500 ko
$tpln->fileControl('Image', false, '500 ko', 'jpg')->imageDimension('', '<=', 500, '<=', 500);
$tpln->required('Url')->url();
$tpln->max('Comment', 50);
if ($tpln->formIsValid()) {
示例#9
0
文件: index.php 项目: h2lsoft/tpln
<?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();