Быстрый легкий, шаблонизатор
1 Аргумент: Дериктория шаблона (Необязательный)
2 Аргумент: расширение файлов шаблона (необязательный)
1 Аргумент: ссылка на файл шаблона без дериктории шаблона и расширения файла если оно присвено ранее
2 Аргумент: Массив с данными где key будет заменен на value
3 Аргумент: Массив с Блоками [admin]Я админ[/admin] где key это идентификатор блока а value это определение показывать содержимое блока или нет (По умолчанию false)
4 Аргумент: ключ массива с данными шаблона (По умолчанию main)
5 Аргумент: не читать файл повторно если он был прочитан ранее
Содержимое файла index.php :
// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';
// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');
// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
'{test-output}' => 'Test-output',
'{test-output2}' => 'Test-output2',
'{test-output3}' => 'Test-output3',
));
Содержимое файла /templates/index.tpl :
<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>{test-output}</p>
<p>{test-output2}</p>
<p>{test-output3}</p>
</body>
</html>
Браузер
Test-output
Test-output2
Test-output3
Содержимое файла index.php :
// Обратите внимание что переменная равна true
$admin = true;
// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';
// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');
// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
'{test-output}' => 'Test-output',
'{test-output2}' => 'Test-output2',
'{test-output3}' => 'Test-output3',
), array(
'admin' => $admin // [admin]Я админ[/admin]
));
Содержимое файла /templates/index.tpl :
<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
[admin]<p>Я админ</p>[/admin]
<p>{test-output}</p>
<p>{test-output2}</p>
<p>{test-output3}</p>
</body>
</html>
Браузер
Я админ
Test-output
Test-output2
Test-output3
Содержимое файла index.php :
// Обратите внимание что переменная равна true
$admin = true;
// Инклудим класс шаблонизатора
include __DIR__ .'/Templater.php';
// Обьявляем класс
$tpl = new Templater('/templates/', '.tpl');
// Компилируем шаблон page
$tpl->compile("page", array(
'{test}' => 'Скомпилирована',
), false, 'page');
// Компилируем и выводим в браузер
echo $tpl->compile("index", array(
'{test-output}' => 'Test-output',
'{test-output2}' => 'Test-output2',
'{test-output3}' => 'Test-output3',
'{page}' => $tpl->get['page'] // Ранее скомпилированный шаблон page
), array(
'admin' => $admin // [admin]Я админ[/admin]
));
Содержимое файла /templates/page.tpl :
Подстраница {test}
Содержимое файла /templates/index.tpl :
<DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p>{page}</p>
[admin]<p>Я админ</p>[/admin]
<p>{test-output}</p>
<p>{test-output2}</p>
<p>{test-output3}</p>
</body>
</html>
Браузер
Подстраница Скомпилирована
Я админ
Test-output
Test-output2
Test-output3