Registering own macro in config turns off snippets
- medhi
- Generous Backer | 255
I would like to set my own macro. So I've created a new class, which extends
Latte\Macros\UIMacros
:
namespace MyProject\Latte\Macros;
class ThemeMacros extends Latte\Macros\UIMacros
{
public static function install(Latte\Compiler $compiler)
{
$me = new static($compiler);
$me->addMacro('myMacro', array($me, 'myMacro'));
}
/**
* {myMacro} macro extends {include #block} macro and tests if block exists
*
*/
public function macroMyMacro(MacroNode $node, PhpWriter $writer)
{
return 'if (isset( $_l->blocks[\'' . $node->args . '\'])) { ' . $this->macroInclude($node, $writer) . '; }';
}
}
But if I register this class in config:
nette:
latte:
macros:
- MyProject\Latte\Macros\ThemeMacros
MyMacro works fine as expected.
But it causes, that snippets (which is also defined in UIMacros) will stop working. Invalidation of any snippet returns nothing. But Payload object works fine.
Any ideas?
- Aurielle
- Member | 1281
Wouldn't the problem lie in overloaded install()
method? Because
other macros will probably stop working if you won't call parent
method.
Edit: that being said, by quickly looking at the code I don't see how could
you extend the parent method with your own macro registration without
duplicating it (no way to get to $me
).
Last edited by Aurielle (2014-02-22 12:50)
- medhi
- Generous Backer | 255
Problem is in extending from UIMacros. If extending from MacroSet, everything works fine. If extending from UIMacros, in template PHP header is added this:
// prolog MyProject\Latte\Macros\ThemeMacros
// snippets support
if (!empty($_control->snippetMode)) {
return Nette\Latte\Macros\UIMacros::renderSnippets($_control, $_l, get_defined_vars());
}
Which is probably bad. And you'll tell me to extend MacroSet. OK. But I need to call one of UIMacros macro. How one can do it?
What I need it for? I need alias for {include}
macro, to wrap
it by isset(). I know, it shouldn't be, but this case is special. My special
macro will be used by template-makers, which won't know, if included block
exists or not.