How to create new macro in Latte?

3 years ago

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.

3 years ago

Felix
Nette Core | 882
+
+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/…/configuring

3 years ago

droa22
Member | 6
+
0
-

Thanks Felix.