Nette Framework - Custom Attribute Macros

What is the best way to define new attribute macros in the Nette Framework ?

Also, is it possible to do this in the configuration file?

+7
source share
1 answer

Defining your own macro is really simple in the Nette Framework, you must first create a MacroSet:

$latte = new Nette\Latte\Engine; $set = new Nette\Latte\Macros\MacroSet($latte->compiler); 

then create a new macro using args:

 $set->addMacro('if', 'if (%node.args):', 'endif'); 

And the solution for your second question:

 Class MyMacroSet extends Nette\Latte\Macros\MacroSet { public static function install(Nette\Latte\Compiler $compiler) { $compiler->addMacro('if', 'if (%node.args):', 'endif'); } } 

and in config.neon you can register your macrosset:

 nette.latte: setup: - MyMacroSet::install($service->compiler) 
+14
source

All Articles