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 wor
In Laravel 5 we now have a hasSection
method we can call on a View
facade.
You can use View::hasSection
to check if @yeild
is empty or not:
@if(View::hasSection('title'))
@yield('title')
@else
Static Website Title Here
@endif
This conditional is checking if a section with the name of title was set in our view.
Tip: I see a lot of new artisans set up their title sections like this:
@section('title')
Your Title Here
@stop
but you can simplify this by just passing in a default value as the second argument:
@section('title', 'Your Title Here')
The hasSection
method was added April 15, 2015.