|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Erriour Smarty n00b
Joined: 11 Jan 2018 Posts: 1
|
Posted: Thu Jan 11, 2018 4:22 am Post subject: Inheritance of templates when compiled using PHP |
|
|
Есть несколько шаблонов. Например:
Code: |
{* Базовый шаблон *}
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8" />
<title>Главная</title>
</head>
<body>
<div class="main_block">
{$content}
</div>
</body>
</html>
|
Code: |
{* Шаблон внутренней страницы, например, обратной связи *}
<form method="POST">
<input type="text" name="to_username" />
<textarea name="to_text"></textrea>
<select name="branch">
{$branches}
</select>
<button type="submit">Отправить</button>
</form>
|
Code: |
{* Шаблон ветки *}
<option value="{$value}" class="{$color_class}">{$title}</option>
|
Нужно, начиная с последнего шаблона откомпилировать всё и вывести на экран пользователю.
Вот, например, так это можно было делать в DLE (в этом движке не используется Smarty, но реализация приближённо на него похожа):
Code: |
//Допустим, компилируем страницу с логами
function newtpl($tmpl){
$tpl = new dle_template();
$tpl->dir = TEMPLATE_DIR;
$tpl->load_template($tmpl);
return $tpl;
}
$tpl->load_template('logs.tpl');
$tplb = newtpl('logs_line.tpl');
foreach($db->super_query('запрос') as $row){
$tplb->set('{something}' $row['something']);
$tplb->compile('loglist');
}
$tpl->set('{logs}', $tplb->result['loglist']);
$tpl->compile('content');
//И дальше сам движок пихает главный шаблон main.tpl и заменяет в нём {content} на откомпилированное
|
Возможно ли так сделать? В документации ничего похожего не нашёл... |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Jan 11, 2018 6:32 am Post subject: |
|
|
А параметры <select>'а проще строить с помощью встроенного рендера. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|