首页 > 解决方案 > 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()

在此处输入图像描述

任何帮助表示赞赏。

标签: phplaravel

解决方案


您需要使用以下语法在布局刀片视图中包含插槽:

{!! $slot !!}

这样,slot将呈现数据并解释 html。如果您只是使用{{ $slot }},则 html 将显示为文本(已转义)。

请谨慎使用{!! $slot !!},因为$slot内容中的任何 javascript 也会被执行,从而使您面临潜在的 XSS 攻击。

确保信任内容的来源(例如仅管理员)或在用户发布的情况下对其进行清理。


推荐阅读