Nette 2.2 – Unknown macro

bohacf
Member | 3
+
0
-

Hi,
after migration from 2.1 to 2.2 I have problem with registering my own macro. My macros I registering in BasePresenter. But app falls on Latte\CompileException „Unknown macro {scache}“.

Do you have any idea how to fix it?

<?php
// BasePresenter:
public function createTemplate($class = NULL) {
    $template = parent::createTemplate($class);

    $latteEngine = new Nette\Latte\Engine;

    $compiler = $latteEngine->getCompiler();
    Nette\Bridges\FormsLatte\FormMacros::install($compiler);
    $macros = new Latte\Macros\MacroSet($compiler);
    $macros->addMacro('scache', '?>?<?php echo strtotime(date(\'Y-m-d hh \')); ?>"<?php');
    ...
?>
Jan Tvrdík
Nette guru | 2006
+
+2
-

Well, that is because you create new instance of Nette\Latte\Engine instead of using the existing one.

protected function createTemplate($class)
{
    $template = parent::createTemplate($class);
    $latte = $template->getLatte();
    $compiler = $latte->getCompiler();
    ...

    return $template;
}

Comments

bohacf:

Works perfectly – thanks a lot!

about a month ago
bohacf:

But if I have file template, $template->getLatte() returns null.

Solution:

<?php
  // old style: $template = new \Nette\Templating\FileTemplate($fileName);
  $latte = new \Latte\Engine();
  $template = new \Nette\Bridges\ApplicationLatte\Template($latte);
  $template->setFile($fileName);
?>
about a month ago

Board footer

Nette Tracy Latte Tester Login Register Česká verze