Closed klkvsk closed 8 years ago
It's possible. Is it really so necessary?
Real world example:
I define a custom function for localizing strings: $fenom->addFunctionSmart("i", "Localizer::translate")
, so I can write in template {i "Hello"}
.
Then I define another function, that somehow decorates a string, and want to pass my localized string into it, I would want to write something like: {widget (i "Hello") }
. But I cant. There are workarounds, of course, but they're not as readable as this.
Also, I found out that top-level functions are available in template. But if they used as arguments, they compile, but do not work. With {i strtoupper("foo")}
"i" would still get "foo" as argument. Looks like a bug.
And since calling of top-level user-defined functions is available, maybe also add support for calling static methods?
You may use modifiers:
$fenom->addModifier('i', "Localizer::translate")
and then use it
{widget "Hello"|i }
or
{i "foo"|up}
But i planned this feature. First need analyze, may be some ninja-bugs or conflicts with the lexer.
I thought about static methods in templates, it is good idea to have can use {Fenom\TestCase::dots("string")}
. Also need add security option for disable call static methods.
P.S. i test bug {i strtoupper("foo")}
Use modifiers
When using custom functions, it would be great to be able to nest them like so:
{func1 "foo" (func2 "bar")}
And this would be rendered as:<?= func1("foo", func2("bar")); ?>
Is this possible?