F
Filamentβ€’15mo ago
Lara Zeus

get breadcrumbs in a render hook

how I can access breadcrumbs in a render hook I want to move them to the topbar
->renderHook(
'panels::topbar.start',
fn (): View => view('filament.hooks.lang'),
)
->renderHook(
'panels::topbar.start',
fn (): View => view('filament.hooks.lang'),
)
and my view:
<div>
@if ($breadcrumbs)
<x-filament::breadcrumbs
:breadcrumbs="$breadcrumbs"
class="mb-2 hidden sm:block"
/>
@endif
</div>
<div>
@if ($breadcrumbs)
<x-filament::breadcrumbs
:breadcrumbs="$breadcrumbs"
class="mb-2 hidden sm:block"
/>
@endif
</div>
found this but where are the eggs πŸ˜… $breadcrumbs coming from!? https://discord.com/channels/883083792112300104/883084832387760148/1141060061439987782
5 Replies
Lara Zeus
Lara ZeusOPβ€’15mo ago
with the posted code I get Undefined variable $breadcrumbs it's never set!
krekas
krekasβ€’15mo ago
There's a breadcrumb blade component. Maybe you need to add it where you want to show them?
Dennis Koch
Dennis Kochβ€’15mo ago
There should be a method on the page Page::getBreadcrumbs(). But I don't know how to access the current page in a render hook πŸ˜…
Patrick Boivin
Patrick Boivinβ€’15mo ago
Yeah, the render hooks are disconnected from the page itself. A workaround I'm using to prepare data in the page and make it available to a render hook is the View::share('name', 'value') method. This effectively creates a global variable for all views, so use carefully (ie. add a a custom prefix or something) This works because the page component and its Blade view gets rendered before the rest of the layout (logically...)
Lara Zeus
Lara ZeusOPβ€’15mo ago
thanks, the ui not an issue, the issue how to get breadcrumbs for the current page that is the question πŸ˜‚ this is a good idea. the problem is I think I have to send the page to a global var within every page or at least in every resource.. and I have some packages resources, cant do anything about it thanks everyone, I guess I'll convince them it's better to keep the breadcrumbs in current place πŸ˜‚
Want results from more Discord servers?
Add your server