How to create a macro allowing to include a template
- Wintermute
- Member | 13
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.
- Ondřej Kubíček
- Member | 494
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 => ...}
- Wintermute
- Member | 13
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 ?
- Milo
- Nette Core | 1283
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.
- David Matějka
- Moderator | 6445
probably more relevant is macroInclude in CoreMacros which is used for file inclusion, the one in BlockMacros is used for blocks
- Wintermute
- Member | 13
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 ?