php - Laravel View::make 不渲染
问题描述
我正在制作具有动态布局的 Laravel 包。
$this->layout = View::make($this->layout);
$this->layout->header = __($this->form_name);
$this->layout->slot = View::make('form-generator::form')
->with('fields', $this->fields)
->with('route_name', $this->routeName)
->with('update_route_obj', $this->updateRouteObj); // this is not rendering
这是我从中得到的转储dd($this->layout)
Illuminate\View\View {#1392 ▼
#factory: Illuminate\View\Factory {#1373 ▶}
#engine: Livewire\CompilerEngineForIgnition {#1387 ▶}
#view: "layouts_admin.app"
#data: array:2 [▼
"header" => "Create Category"
"slot" => Illuminate\View\View {#1400 ▶}
]
#path: "/resources/views/layouts_admin/app.blade.php"
}
这是我从View::make()
任何帮助表示赞赏。
解决方案
您需要使用以下语法在布局刀片视图中包含插槽:
{!! $slot !!}
这样,slot
将呈现数据并解释 html。如果您只是使用{{ $slot }}
,则 html 将显示为文本(已转义)。
请谨慎使用{!! $slot !!}
,因为$slot
内容中的任何 javascript 也会被执行,从而使您面临潜在的 XSS 攻击。
确保信任内容的来源(例如仅管理员)或在用户发布的情况下对其进行清理。
推荐阅读
- c# - 这是下面的静态方法线程安全吗?有人可以指导我如何使其线程安全吗?
- apache-kafka - 谁在 Apache Kafka 中跟踪消费者的最后读取消息偏移量?
- javascript - 如何从数组中获取数组?
- php - laravel7 覆盖供应商包类
- python - 清理经纬度数据
- python - float() 参数必须是字符串或数字,而不是 'csr_matrix'
- css - 如何在 Smelte.js 中使选择元素透明?
- ios - 如何将 TextField 中的更改传达给另一个同级视图(Swift UI、Xcode 11.5、macOS Catalina)
- android - Android主屏幕小部件:无法更改ImageButton图像资源
- javascript - 具有特殊 id 的 Vue-js 调用对象