问题
How I can get content from @yield
in PHP?
Example I have in app.blade.php:
@yield('image-url', asset('/img/metaog.png?2'))
I want getimagesize from image-url:
<?php
$image = getimagesize(yield('image-url', asset('/img/metaog.png?2')));
$width = $image[0];
$height = $image[1];
?>
How I can get this correctly? My code is not working.
回答1:
Depending on what version of Laravel
View::getSections()['image-url']
In 5.5
View::getSection('image-url', 'your default value')
That will get what was assigned to that named section. You will have to do your check to see if it has anything still. If using the first method you should be checking if that array key actually exists.
You can use View::hasSection(...)
to check if the section exists at all, if needed.
来源:https://stackoverflow.com/questions/47847610/laravel-yield-in-code-php