Laravel - Check if @yield empty or not

后端 未结 17 2226
醉梦人生
醉梦人生 2021-01-31 02:08

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         


        
17条回答
  •  天命终不由人
    2021-01-31 02:38

    I have a similar problem with the solution:

    @section('bar', '')
    @hasSection('bar')
    
    @yield('bar')
    @endif //Output

    The result will be the empty

    Now, my suggestion, to fix this, is

    @if (View::hasSection('bar') && !empty(View::yieldContent('bar')))
    
    @yield('bar')
    @endif

提交回复
热议问题