Latte šablona vytažená z DB

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
tatyalien
Člen | 239
+
0
-

Prosím nekamenujte mě, ale jak rozchodit latte filtr na vytažené data z DB? Chtěl bych si uložit do DB defakto celou latte šablonu s formulářema atd… a v textové šabloně měl jen:

{block content}
{$data|template}
{/block}

Procházel jsem fórum a narazil jen na jeden helper, kterej jsem si trochu upravil, ale skonočí mě to na chybě: Undefined variable: _control

    public function renderDefault()
    {
        $_this = $this;
        $this->template->registerHelper('template', function($text) use ($_this) {
            $template = new Nette\Templating\Template();
            $template->presenter = $template->control = $_this;
            $template->registerFilter(new Nette\Latte\Engine);
            $template->setSource($text);
            $txt=$template->__toString();
        });

	$this->template->data = 'Ahoj<br />{control changePasswordForm} tst...';
    }
tatyalien
Člen | 239
+
0
-

Děkuji, funguje.

        $_this = $this;
        $this->template->registerHelper('template', function($text) 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é
            $template->user = $_this->user;
            $template->baseUri = $_this->template->baseUri;
            $template->basePath = $_this->template->basePath;
            // flash message
            $presenter = $_this->getPresenter(FALSE);
            if ($presenter->hasFlashSession()) {
                $id = $_this->getParameterId('flash');
                $template->flashes = $presenter->getFlashSession()->$id;
            } else {
                $template->flashes = array();
            }
            $template->setSource($text);
            $txt=$template->__toString();
            return $txt;
        });

Editoval tatyalien (5. 10. 2012 12:51)