Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Inheritance of templates when compiled using PHP

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian
View previous topic :: View next topic  
Author Message
Erriour
Smarty n00b


Joined: 11 Jan 2018
Posts: 1

PostPosted: Thu Jan 11, 2018 4:22 am    Post subject: Inheritance of templates when compiled using PHP Reply with quote

Есть несколько шаблонов. Например:
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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Jan 11, 2018 6:28 am    Post subject: Reply with quote

Смотри теги {extends} и {block}.
Примеров по форуму полно. В том числе довольно сложных, например https://www.smarty.net/forums/viewtopic.php?t=25486
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Jan 11, 2018 6:32 am    Post subject: Reply with quote

А параметры <select>'а проще строить с помощью встроенного рендера.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Russian All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP