How to create new macro in Latte?

Notice: This thread is very old.
droa22
Member | 6
+
0
-

I see that macros are defined in file vendor/nette/nette/Nette/Latte/Macros/UIMacros.php… but where is the best place for add new macro in my project and don't change the original code of nette?.

My idea:

// someTemplate.latte
{addCss '/folder1/folder2/file.css'}

is equivalent to:

// someTemplate.latte
{$presenter->myContainerForCss->addCss('/folder1/folder2/file.css')}

myContainerForCss is my component for render and min css in my templates.

Felix
Nette Core | 1183
+
+2
-

Best way is in config file.

latte:
    xhtml: yes  # default is no
    macros:
        - App\MyLatteMacros::register  # static method, classname or callable

https://doc.nette.org/en/configuring

droa22
Member | 6
+
0
-

Thanks Felix.