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
Use View::hasSection
to check if a section is defined and View::getSection
to get the section contents without using the @yield
Blade directive.
<title>{{ View::hasSection('title') ? View::getSection('title') . ' - App Name' : 'App Name' }}</title>
Complete simple answer
<title> Sitename.com @hasSection('title') - @yield('title') @endif </title>
why not pass the title as a variable View::make('home')->with('title', 'Your Title')
this will make your title available in $title
@hasSection('content')
@yield('content')
@else
\\Something else
@endif
see "Section Directives" in If Statements - Laravel docs
The way to check is to not use the shortcut '@' but to use the long form: Section.
<?php
$title = Section::yield('title');
if(empty($title))
{
$title = 'EMPTY';
}
echo '<h1>' . $title . '</h1>';
?>
Building on Collin Jame's answer, if it is not obvious, I would recommend something like this:
<title>
{{ Config::get('site.title') }}
@if (trim($__env->yieldContent('title')))
- @yield('title')
@endif
</title>