我知道Laravel-blade allows us to define sections of code,但我想知道是否有可能在定义它的同一文件中清除或重新定义一个节。
例如,如下所示:
@section('scripts')
<script src="/example.js"></script>
@endsection
//something like
@section('scripts')
// nothing
@endsection
// now the 'scripts' stack is an empty block of code.
//print
{{ @yield('scripts') }}
发布于 2021-04-10 01:21:06
我已经想出了一种方法,只需在常规php中使用ob_start()
即可。
@php
ob_start();
@endphp
// write blade code here
@php
$scripts = ob_get_contents();
ob_end_clean();
@endphp
//print
{!! $scripts !!}
https://stackoverflow.com/questions/67022756
复制相似问题