Use function without class?
Closed this issue · 1 comments
scramatte commented
Does it possible to use function without embed them into a class ?
I mean for example:
class Formatters {
public static function dummy() {
return 'hello world';
}
}
...
$template = "{{dummy()}}F{{date.format('Ymd')}}-{{sequence.format(8)}}";
$result = $render->renderTemplateString(
$template,
[
'date' => new DateFormatter,
'sequence' => new SequenceFormatter,
'dummy' => Formatters::dummy,
]
...
wol-soft commented
Hi, as of version 1.9.0 you can use callbacks directly in your code. Compare the test cases at https://github.com/wol-soft/php-micro-template/blob/master/tests/RenderTest.php#L369.
Your example throws a PHP syntax error as the callable is defined wrong. Instead of Formatters::dummy
you must use [Formatters::class, 'dummy']
.
Cheers