Renaming macro ‘_’ to any string stops escaping
Notice: This thread is very old.
- Daniel
- Member | 3
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