Where to put the code for user-defined Tags?

romal
Member | 16
+
0
-

I want to create my own tag.
I have read https://latte.nette.org/en/develop#…
But I didn't understand in what file to put this code.
index.php? Bootstrap.php? Or some other file?

CZechBoY
Member | 3608
+
0
-

Depends on how you use Latte. If you use mvc nette, then you should probably create some latte factory for this setting.

romal
Member | 16
+
0
-

CZechBoY wrote:

Depends on how you use Latte. If you use mvc nette, then you should probably create some latte factory for this setting.

Yes, MVC Nette.
$latte = new Latte\Engine;
$set = new Latte\Macros\MacroSet($latte->getCompiler());
$set->addMacro(‘if’, ‘if (%node.args):’, ‘endif’);
But, in what file to put this 3 lines?

romal
Member | 16
+
0
-

Sorry, but I'm a noob and still do not understand.

For example how to translate

$set->addMacro(‘if’, ‘if (%node.args):’, ‘endif’)

into config file?

CZechBoY
Member | 3608
+
0
-

i hope sth like this

latte.macros:
    - MyApp\Templating\MyIfMacroFactory
namespace MyApp\Templating;

class MyIfMacrosFactory
{
    public function install(\Latte\Compiler $compiler)
    {
        $set = new \Latte\Macros\MacroSet($compiler);

        $set->addMacro(‘if’, ‘if (%node.args):’, ‘endif’)

        return $set;
}