Blade directive sets all expressions to string. #45026
Replies: 4 comments
-
please provide more details, like your directive definition in AppServiceProvier. |
Beta Was this translation helpful? Give feedback.
-
Directives registered via When it encounters your custom directives, i.e. |
Beta Was this translation helpful? Give feedback.
-
Another example
if I try this Sorry for my english 😌 |
Beta Was this translation helpful? Give feedback.
-
For the people who still come across this (because I did), listen up: It isn't actually an issue. It's how the Blade directive works. You pass an expression, and you need to have the expression within the returned string, because that's how it is evaluated. So, say you have: $var = 'Hello';
@world($var); // Hello World
Blade::directive('world', function ($expression) {
dump($expression); // $var
return '<?php echo $expression World'?>
}); Don't forget to clear view cache after changing the directive. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I see this as a limitation when we need to create a blade directive, in the documentation example it makes sense in terms of how we can have a datetime directive.
But I found a limitation in case we don't want to send a Datetime instance but a string with date.
Within my example I created a datetime directive and with it I send a string that is a date.
@datetime("2022-11-18")
If inside the directive function I do
dd($expression)
, it will return""2022-11-18""
I've used
Blade::if
and didn't have this problem with it, shouldn't we be able to do complex things with the Blade directive?Beta Was this translation helpful? Give feedback.
All reactions