Twig implementation..complete swap from latter to twig or plugin type
- onlyorange
- Člen | 2
Hello, I am pretty new to this nette framework.
so question here, anyone ever done using twig template engine under nette
framework?
is there possible way to do it? or any existing plugins? or tutorial?
latte seems pretty straight forward. but my front-end dev team really want to use twig instead of latte so..
any help will be appreciated.
Thank you in advance.
- hrach
- Člen | 1838
You need just implement ITemplate/IFileTemplate with your twig support and override Control::createTemplate(). Well, you need it override for presenter and controls, so create BasePresenter and BaseControl with this overridden method.
- onlyorange
- Člen | 2
hm…sorry but can you give me a quick sample?
It will be much easier to understand it if you can…
- hrach
- Člen | 1838
I have never use twig… take it just as a example:
class NetteTwig implements Nette\Templating\IFileTemplate
{
private $file;
private $variables;
public function setFile() { $this->file = $file; }
public function getFile() { return $this->file; }
public function render() {
$loader = new Twig_Loader_Filesystem(dirname($this->file));
$twig = new Twig_Environment($loader, array(
'cache' => '/path/to/compilation_cache',
));
$thig->render(basename($this->file), $this->variables);
}
public function __set($var, $val) { $this->variables[$var] = $val; }
public function &__get($var) { return $this->variables[$var]; }
public function __isset() {} // ... etc
}
And then:
class BasePresenter extends Nette\Application\UI\Presenter
{
public function createTemplate()
{
$template = new NetteTwig();
$template->presenter = $template->control = $this;
// ...
return $template;
}
}
class BaseControl extends Nette\Application\UI\Control
{
public function createTemplate()
{
$template = new NetteTemplate();
$template->presenter = $this->getPresenter(FALSE);
$template->control = $this;
// ...
return $template;
}
}
Editoval hrach (10. 10. 2013 14:43)