How to register global macros with Neon?
Notice: This thread is very old.
- MartyIX
- Member | 217
A simple implementation of an extended Latte Engine that register my macros can be made like this:
namespace MyProject\Application\Latte;
class Engine extends \Nette\Latte\Engine
{
public function __construct(\Nette\DI\IContainer $container)
{
parent::__construct();
$macros = ['css', 'js', 'confirm', 'rfcLink'];
foreach ($macros as $item) {
$class = "\MyProject\Application\Latte\Macros\\" . ucfirst($item) . "Macro";
$class::install($this->compiler);
}
return $this;
}
}
I would like to register the class above as the default Latte Engine class. I tried to use the syntax below in config.neon:
nette:
latte:
class: \MyProject\Application\Latte\Engine
but it throws the exception: Nette\InvalidStateException: “Found sections ‘latte’ in configuration, but corresponding extensions are missing.”
https://doc.nette.org/cs/configuring#…
EDIT: I know that I can register macros in a presenter and in a control but the approach above suits my needs better.
Last edited by MartyIX (2012-08-15 10:11)