andyh81's avatar

How to set a dynamic title using Volt

I'm getting stuck when trying to set the page title from my full page Volt component to the app.blade layout page title.

I'm setting the title property in users.blade.php:

use App\Models\User;
use function Livewire\Volt\{state,title};

$users = User::all();
state(
    [
        'users' => $users,
    ]
);

title('Users');

Then in my app.blade layout file I'm pulling it in like so:

<title>{{ $title ?? config('app.name', 'Laravel') }}</title>

Any thoughts on what I'm doing wrong?

0 likes
3 replies
hupp's avatar

@andyh81

Try with this :

<title>{{ Livewire\Volt\getSharedData()['title'] ?? config('app.name', 'Laravel') }}</title>

andyh81's avatar

@hupp Thanks for the reply, I'll give this a try! Can you tell me where you found this? I looked through the docs and didn't see this.

Please or to participate in this conversation.