php - 如何清除blade.php中定义的部分
问题描述
我知道Laravel-blade 允许我们定义代码段,但我想知道是否可以清除或重新定义与定义相同的文件中的部分。
例如,类似:
@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') }}
解决方案
我已经找到了一种方法,只需ob_start()
在常规 php 中使用即可。
@php
ob_start();
@endphp
// write blade code here
@php
$scripts = ob_get_contents();
ob_end_clean();
@endphp
//print
{!! $scripts !!}
推荐阅读
- ios - 单击内部选项卡时保持 ScrollView 位置(刷新内部数据)
- reactjs - 在 JSX 文件上使用 Babel>Transform 时 Sublime Text 报告语法错误
- javascript - 使用文本框进行交叉过滤
- python - 如何在python中将第一行的结束时间作为第二行的开始时间
- java - 使用停止按钮停止无限循环
- ios - 处理 RxSwift 重试和错误处理的最佳实践是什么
- android - Android Sqlite 数据库未将数据存储在新表中
- c# - 无法从 OrmLiteConfigExtensions (ServiceStack.OrmLite.Core) 加载 System.ComponentModel.Annotations
- laravel - Laravel 包未完全删除
- c# - 如何在 MVC Core 控制器抛出异常时不丢弃的中间件中设置 HTTP 响应标头?