Latte – compile text from database
- Hachik
- Member | 10
Hi everyone, I just have a problem with how compile text or template saved in database use Latte filter. For example
Seamlessly parallel task multimedia based technologies without error-free sources. Globally facilitate
{control attachment:files 1}
Seamlessly parallel task multimedia based technologies without error-free sources. Globally facilitate go forward
– where I want replace “{control attachment:files 1}” with component. Please help me :)
- stefi023
- Member | 71
Hachik wrote:
You should use Nette\Templating\Template
and its
setSource()
method.
Eg. you can write your own helper:
presenter/control:
public function renderDefault() {
$this->template->stringContainingLatteFromDatabase = ... ; //dont know where you get it
$this->template->registerHelper('stringTemplate',callback($this,'stringTemplate'));
}
public function stringTemplate($string) {
return $this->createTemplate('Nette\Templating\Template')
->setSource($string)
->render();
}
template:
{$stringContainingLatteFromDatabase|stringTemplate}
Remember that, if you do not create the template via the
Nette\Application\UI\Control::createTemplate
method, you have to
register all its helpers, basic variables, etc (see Application.UI.Control)
I hope it's clear :)
Last edited by stefi023 (2012-06-25 17:03)
- Hachik
- Member | 10
Super that exactly what I need. I just repair code like
public function stringTemplate($string) {
return (string)$this->createTemplate('Nette\Templating\Template')
->setSource($string);
}
without call render method
because I would like just use compile string for next use.
Last edited by Hachik (2012-06-27 21:45)