Laravel @yield in code php

守給你的承諾、 提交于 2019-12-24 00:35:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!