Примеры в отдельную папку

This commit is contained in:
Федор Подлеснов 2015-12-11 12:14:30 +03:00
parent 0f62ba3a29
commit 313413931b
7 changed files with 6 additions and 6 deletions

19
examples/example.php Normal file
View file

@ -0,0 +1,19 @@
<?php
require_once '../klein.php';
function title($x) {
return ucfirst($x);
}
$tpl = new Klein();
$tpl->compile('tempalte.html');
echo $tpl->render(array(
'pagename' => 'awesome people',
'authors' => [['name' => 'Paul', 'age' => 10], ['name' => 'Jim', 'age' => 11], ['name' => 'Jane', 'age' => 12]],
'city'=> [
'Yaroslaval' => 1,
'Moscow' => 2
]
));

35
examples/example2.php Normal file
View file

@ -0,0 +1,35 @@
<?php
$data = array (
array (
'id' => 0,
'id_table' => 0,
'name' => '',
'header' => 'Наименование муниципального образования',
'comment' => '',
'colspan' => 0,
'rowspan' => 4,
'row' => 0,
'position' => 0,
'type' => '',
),
array (
'id' => 1,
'id_table' => 0,
'name' => '',
'header' => '',
'comment' => 'Над строкой - Прибыло всего (взрослых и детей)',
'rowspan' => 0,
'row' => 0,
'position' => 1,
'type' => '',
)
);
require_once '../klein.php';
$tpl = new Klein();
$tpl->compile('template2.html');
echo $tpl->render(array('content' => $data));

10
examples/example3.php Normal file
View file

@ -0,0 +1,10 @@
<?php
$data = array('phedor', 'andrey');
require_once '../klein.php';
$tpl = new Klein();
$tpl->compile('template3.html');
echo $tpl->render(array('names' => $data));

18
examples/tempalte.html Normal file
View file

@ -0,0 +1,18 @@
<h1>{{ pagename|title }}</h1>
<ul>
{% for author in authors %}
<li {% if loop.first %}class="first"{% endif %}{% if loop.last %}class="last"{% endif %}>
<div class="name">{{ author.name }}</div>
<div class="age">{{ author.age }}</div>
</li>
{% endfor %}
{% for key, value in city %}
<li>
<div class="value">{{ value }}</div>
<div class="key">{{ key }}</div>
</li>
{% endfor %}
</ul>

7
examples/template2.html Normal file
View file

@ -0,0 +1,7 @@
<div>
{% for var in content %}
{% for key, value in var %}
<b>{{key}} - {{value}}</b>
{% endfor %}
{% endfor %}
</div>

9
examples/template3.html Normal file
View file

@ -0,0 +1,9 @@
{% macro hello(name) %}
<em>hello, {{ name }} {{! name }}<em>
{% endmacro %}
<div>
{% for name in names %}
{{ hello(name) }}
{% endfor %}
</div>