Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel @yield in code php

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.

like image 845
Jadasdas Avatar asked Jan 03 '23 01:01

Jadasdas


1 Answers

In Laravel 5.5 and up:

View::getSection('image-url', 'your default value')

In Laravel 5.4 and below:

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

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.

like image 109
lagbox Avatar answered Jan 05 '23 16:01

lagbox