vykreslení šablony view z DB
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- tatyalien
- Člen | 239
V presenteru:
$_this = $this;
$this->template->registerHelper('template', function($text, $data='', $skin='') use ($_this) {
$template = new Nette\Templating\Template();
$template->control = $template->_control = $_this;
$template->presenter = $template->_presenter = $_this->getPresenter(FALSE);
$template->registerFilter(new Nette\Latte\Engine);
// dodané proměnné
$presenter = $_this->getPresenter(FALSE);
$template->user = $_this->user;
$template->baseUri = $_this->template->baseUri;
$template->basePath = $_this->template->basePath;
$template->myPresenter = $presenter->name;
$template->myView = $presenter->view;
$template->data = $data;
$template->skin = $skin;
// flash message
if ($presenter->hasFlashSession()) {
$id = $_this->getParameterId('flash');
$template->flashes = $presenter->getFlashSession()->$id;
}
if (!isset($template->flashes) || !is_array($template->flashes)) {
$template->flashes = array();
}
// dodání helperu
$template->registerHelper('prevodDatumu', function($value, $format='d.m.Y H:i:s') {
if(trim($value) == '') {
return '';
}
return date($format, strtotime($value));
});
// naplnění šablony datama
$template->setSource($text);
$txt=$template->__toString();
return $txt;
});
Toto mě funguje, ale musím použít šablonu s:
{block content}
{!$layoutData|template:$settings, $skin}
{/block}
Je nějaký způsob, kde bych v render metodě v presenteru nastavil, aby rovnou data z DB vykreslil, bez existence latte šablony daného view?
Například
public function renderTest($id)
{
// 1) vytažení dat z DB pro šablonu - například přehled článků
// 2) vytažení samotné šablony z DB kde už je {block content}...html... {foreach $articles}...{/foreach}...{/block}
// 3) vykreslení šablony bez existence test.latte
}
Editoval tatyalien (10. 11. 2012 20:52)