Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nette Framework - custom attribute macros

Tags:

php

nette

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

Moreover, would it be possible to do so in the config file?

like image 703
Mikulas Dite Avatar asked Feb 26 '12 19:02

Mikulas Dite


1 Answers

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

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

then create new Macro with args:

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

And 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 macroSet:

nette.latte:
                setup:
                        - MyMacroSet::install($service->compiler)
like image 75
pilec Avatar answered Sep 28 '22 11:09

pilec