-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[5.2] Allow for @has in blade #12866
Conversation
Okay. styleci makes things annoying. If necessary I can squash all commits down. |
I also can't find where blade gets tested. |
*/ | ||
protected function compileHas($expression) | ||
{ | ||
return "<?php if(!empty(trim(\$__env->yieldContent{$expression}))): ?>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use $__env->hasSection to determine whether a section exists.
Actually, yieldContent does check the section is set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should this be changed? To me this seems correct. I want to see whether there is any content to be yielded.
IMHO, you should define the For example, if a section foo
, the |
Ah yes. Perhaps the fix is to check length > 0, rather than empty? |
And should it perhaps be called hasYield? Though to me that is not as clean |
Intuitively, I think |
I have a custom blade directive in one of my projects that works like this:
It yields the section content as it is if exists, if not then the second argument will be displayed. If the third argument has a value it'll yield the section content based on the format. Maybe such directive can be used to provide the same functionality instead of a condition, otherwise I believe |
I would like |
I agree that the endif is strange, and can easily have a Before I make any changes on this then, I'd like to get @taylorotwell input on this. Which direction do you think this should go (if any?). |
I believe you can also already do Does that solve your problem? |
@taylorotwell, the problem is something must show if title section exist, not your example something must show if title doesn't exist |
Yeah, the use case here for me is a conditional one. |
Renamed to |
Great! Today I actually was searching for something like this, in my case I needed to put default HTML content for section, using second argument for Btw, if somebody interested, I used this approach:
|
@taylorotwell Do you want a PR with |
Currently, it is difficult to determine whether something can be @yield'd
Code usage is the same as @if.
Example usage: