Renaming macro ‘_’ to any string stops escaping

Notice: This thread is very old.
Daniel
Member | 3
+
0
-

Hello,
I use standalone Latte and everything work perfectly except one thing.

THIS WORKS
CoreMacros.php

<?php
$me->addMacro('_', array($me, 'macroTranslate'), array($me, 'macroTranslate'));

// some code

public function macroTranslate(MacroNode $node, PhpWriter $writer)
{
	if ($node->closing) {
		return $writer->write('echo %modify($template->translate(ob_get_clean()))');

	} elseif ($node->isEmpty = ($node->args !== '')) {
		return $writer->write('echo %modify($template->translate(%node.args))');

	} else {
		return 'ob_start()';
	}
}
?>

In template:

<?php
{_'SOME KEY'}
?>

Output in php:

<?php
echo \view\latte\Runtime\Filters::escapeHtml($template->translate('SOME KEY'), ENT_NOQUOTES)
?>

THIS DOES NOT WORKS
I change only name of macro in CoreMacros.php

<?php
$me->addMacro('translate', array($me, 'macroTranslate'), array($me, 'macroTranslate'));
?>

In template:

<?php
{translate 'SOME KEY'}
?>

Output in php:

<?php
echo $template->translate('SOME KEY')
?>

Renamign causes, that there is no escaping. I have no idea why.

I need two translating macros, because I have two translation sources. Thats why I try to rename macro – I want to duplicate it in future.

Many thanks for any help.
Daniel

Patrik Votoček
Member | 2221
+
0
-

because (auto) escaping for macro _ is hardcoded in Latte

Daniel
Member | 3
+
0
-

Thanks.
On what place in code? It occured to me, I tried to search, but didn't find it. Can I double it for different name?

Last edited by Daniel (2014-05-23 21:09)

David Grudl
Nette Core | 8218
+
0
-

Here https://github.com/…Compiler.php#L536. But it is not nice.

Daniel
Member | 3
+
0
-

Many thanks, that is what I was looking for.

Latte and Tracy is awesome. Especially ‘n’ macro.