You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
When you define a Blade::directive(…) your closure usually gets back a plain expression as a string. However, in a lot of cases I find myself wanting to do one or two things to the arguments in the directive definition - often just small things for the sake of presentation that don’t warrant their own helper function too.
Imagine that BladeCompiler was Macroable and we could do this to accept a new callback and extract the arguments first.
Blade::macro('directiveWithArgs', function ($name, callable$handler) {
Blade::directive($name, function($expression) use ($handler) {
$args = eval("return [{$expression}];");
return$handler(...$args);
});
});
This then lets us define and use new Blade directives with the arguments we want the directive to accept directly, just like you’d normally define a function.
I feel like this drastically lowers the cognitive overload when reading a directive and it doesn’t immediately pass the inner expression off to another function and would love to see it as an option in the future.
The text was updated successfully, but these errors were encountered:
This won't work if you pass to your directives anything else than explicit values. @example($foo) will error because $foo is not defined when view is compiled.
I think the feature could be very useful, but it will require implementing some serious parsing.
When you define a
Blade::directive(…)
your closure usually gets back a plain expression as a string. However, in a lot of cases I find myself wanting to do one or two things to the arguments in the directive definition - often just small things for the sake of presentation that don’t warrant their own helper function too.Imagine that
BladeCompiler
was Macroable and we could do this to accept a new callback and extract the arguments first.This then lets us define and use new Blade directives with the arguments we want the directive to accept directly, just like you’d normally define a function.
I feel like this drastically lowers the cognitive overload when reading a directive and it doesn’t immediately pass the inner expression off to another function and would love to see it as an option in the future.
The text was updated successfully, but these errors were encountered: