渲染钩子
概述
Filament 允许你在框架视图的多个节点渲染 Blade 模板内容。这使得插件可以注入 HTML 到框架中。同时,由于 Filament 不推荐发布视图因其可能会增加破坏性变更的风险,这也对用户很有用。
注册渲染钩子
要注册渲染钩子,你可以在服务提供者或者中间件中调用 FilamentView::registerRenderHook()
。第一个参数是钩子名称,第二个参数返回要渲染的内容的回调函数:
use Filament\Support\Facades\FilamentView;
use Illuminate\Support\Facades\Blade;
FilamentView::registerRenderHook(
'panels::body.start',
fn (): string => Blade::render('@livewire(\'livewire-ui-modal\')'),
);
你也可以在文件中渲染视图内容:
use Filament\Support\Facades\FilamentView;
use Illuminate\Contracts\View\View;
FilamentView::registerRenderHook(
'panels::body.start',
fn (): View => view('impersonation-banner'),
);
可用渲染钩子
面板渲染钩子
panels::body.start
-<body>
之后panels::body.end
-</body>
之前panels::content.end
- 页面内容之后,在<main>
里面panels::content.start
- 页面内容之前,在<main>
里panels::footer
- 页面 footerpanels::global-search.end
- 全局搜索 容器尾部panels::global-search.start
- 全局搜索 容器开始处panels::head.end
-</head>
之前panels::head.start
-<head>
之后panels::page.end
- End of the page content container, also can be scoped to the page or resource classpanels::page.footer-widgets.after
- After the page footer widgets, also can be scoped to the page or resource classpanels::page.footer-widgets.before
- Before the page footer widgets, also can be scoped to the page or resource classpanels::page.header-widgets.after
- After the page header widgets, also can be scoped to the page or resource classpanels::page.header-widgets.before
- Before the page header widgets, also can be scoped to the page or resource classpanels::page.start
- Start of the page content container, also can be scoped to the page or resource classpanels::resource.pages.list-records.table.after
- After the resource table, also can be scoped to the page or resource classpanels::resource.pages.list-records.table.before
- Before the resource table, also can be scoped to the page or resource classpanels::resource.pages.list-records.tabs.end
- The end of the filter tabs (after the last tab), also can be scoped to the page or resource classpanels::resource.pages.list-records.tabs.start
- The start of the filter tabs (before the first tab), also can be scoped to the page or resource classpanels::resource.relation-manager.after
- After the relation manager table, also can be scoped to the page or relation manager classpanels::resource.relation-manager.before
- Before the relation manager table, also can be scoped to the page or relation manager classpanels::scripts.after
- After scripts are definedpanels::scripts.before
- Before scripts are definedpanels::sidebar.nav.end
- 在 侧边栏中,</nav>
之前panels::sidebar.nav.start
- 在 侧边栏中,</nav>
之后panels::sidebar.footer
- Pinned to the bottom of the sidebar, below the contentpanels::styles.after
- After styles are definedpanels::styles.before
- Before styles are definedpanels::tenant-menu.after
- 租户菜单之后panels::tenant-menu.before
- 租户菜单之前panels::topbar.end
- End of the topbar containerpanels::topbar.start
- Start of the topbar containerpanels::user-menu.after
- 用户菜单之后panels::user-menu.before
- 用户菜单之前panels::user-menu.profile.after
- After the profile item in the user menupanels::user-menu.profile.before
- Before the profile item in the user menu