F
Filament2mo ago
Josh

Cleaner way to do this with render hooks?

So I am wrapping a div around a greeting I am putting next to the user avatar to allow me to style things better, I have this which works but i wonder if theres a way to do it that I haven't thought of?
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn () => "<div>"
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn () => view("filament.hooks.header-user-greeting")
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_AFTER,
fn () => "</div>"
);
}
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn () => "<div>"
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn () => view("filament.hooks.header-user-greeting")
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_AFTER,
fn () => "</div>"
);
}
Context; Its the only way I can think to have a div around my greeting and the usermenu dropdown that filament ships with without having to publish views and edit vendor code.
1 Reply
Josh
Josh2mo ago
I've got it to this point
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
function () {
return "<div class='flex items-center'>" . view('filament.hooks.header-user-greeting');
}
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_AFTER,
fn () => "</div>"
);
}
public function boot(): void
{
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
function () {
return "<div class='flex items-center'>" . view('filament.hooks.header-user-greeting');
}
);

FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_AFTER,
fn () => "</div>"
);
}