Laravel - Check if @yield empty or not

后端 未结 17 1975
醉梦人生
醉梦人生 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:34

    Sometimes you have an enclosing code, which you only want to have included in that section is not empty. For this problem I just found this solution:

    @if (filled(View::yieldContent('sub-title')))
        

    @yield('sub-title')

    @endif

    The title H2 gets only displayed it the section really contains any value. Otherwise it won't be printed...

提交回复
热议问题