-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blade::if directive with an argument of 0 is not compiled correctly #24390
Comments
As a workaround you can use a string:
|
@staudenmeir |
that means the fix would look like $expression || $expression === "0"
? /* with argument */
: /* without argument */; which is kinda ugly but behaves a lot more like one would expect it to behave |
I would suggest a stricter comparison: |
@staudenmeir yea that is a much cleaner way to write the same thing 👍 |
Out of curiosity: Why are you using the directive with a fixed value? |
Showing and hiding parts of blades depending on the "organizational level" of a user. We could use names (strings) instead of numbers for the organizational levels but we tend to call them by their numbers (mostly because the names can be confusing). Alternatively we could write different directives per level |
I just saw your edit: Yes, create a pull request and add a test. Since it's a bug fix, you should target the 5.6 branch. |
Description:
Will cause errors when used with
0
(@iseven(0)
).At: https://github.com/laravel/framework/blob/5.6/src/Illuminate/View/Compilers/BladeCompiler.php#L394-L413
The compiler checks if the directive received any arguments and if it didn't it will output a check without an argument. However since
0
is falsy you can't pass0
into a custom blade conditional.Steps To Reproduce:
Add the
iseven
blade conditional to your app service provider and addin a blade template.
expected result would be the
test
but it will throw errors about expecting an argument that it didn't get.The text was updated successfully, but these errors were encountered: