How to create a macro allowing to include a template

about a month ago

Wintermute
Member | 4
+
0
-

Hello !

I use Latte as templating system in my PHP framework, Bluebird.

I created a few templates for form fields which could be included in another template : formtext.html, formcheckbox.html

Is there a way to create a macro wich allow to write something like :

{formtext name => 'title',required => true}

instead of

{include 'formtext.html', name => 'title',required=>true}

?

Thanks.

about a month ago

Ondřej Kubíček
Member | 367
+
+1
-

you can create your own macro, but i think you want a dynamic macro name and i dont think it is possible, not easy way…
but you can create macro with one letter, such as alias. something like this – {i formtext, name => ...}

about a month ago

Wintermute
Member | 4
+
0
-

Hello,

Thanks for your answer.

No, I don't want a dynamic macro.

I would like to know how to write a macro formtext which could call include and pass its arguments.

Could I write a macro which call BlockMacros::macroInclude ?

about a month ago

Milo
Nette Core | 1118
+
0
-

I don't know about some blog post about macro writing in english. In shortcut…

If you want to write a macro, implement the Latte\IMacro and than register own macros for Latte\Compiler. The most easiest way is extending the Latte\Macros\MacroSet, it's a prepared implementation.

Write macro similar to include is quite different. The {include} is one of Latte core macros and is quite tided to core code. Probably copy/paste of code is the easiest way.

Edit:
Wrong link. @DavidMatějka's one below is correct.

about a month ago

David Matějka
Moderator | 5764
+
+1
-

probably more relevant is macroInclude in CoreMacros which is used for file inclusion, the one in BlockMacros is used for blocks

about a month ago

Wintermute
Member | 4
+
0
-

Ondřej Kubíček wrote:
but you can create macro with one letter, such as alias. something like this – {i formtext, name => ...}

Is there a simple way to create an alias for a built-in macro such as include ?