user2840318 user2840318 - 1 year ago 282
PHP Question

Laravel - Check if @yield empty or not

Is it possible to check into a blade view if @yield have content or not?

I am trying to assign the page titles in the views:

@section("title", "hi world")

So I would like to check in the main layout view... something like:

<title> {{ @yield('title') ? ' - '.@yield('title') : '' }} </title>

Answer Source

There is probably a prettier way to do this. But this does the trick.

@if (trim($__env->yieldContent('title')))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download