Laravel @yield在代码php中 [英] Laravel @yield in code php

查看:363
本文介绍了Laravel @yield在代码php中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在PHP中从@yield获取内容?

How I can get content from @yield in PHP?

我在app.blade.php中的示例:

Example I have in app.blade.php:

@yield('image-url', asset('/img/metaog.png?2'))

我要从image-url获取图像大小:

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.

推荐答案

取决于Laravel的版本

Depending on what version of Laravel

View::getSections()['image-url']

在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.

如果需要,可以使用View::hasSection(...)检查该部分是否存在.

You can use View::hasSection(...) to check if the section exists at all, if needed.

这篇关于Laravel @yield在代码php中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆