livewire / volt

Volt is an elegantly crafted functional API for Livewire.
https://livewire.laravel.com/docs/volt
MIT License
312 stars 19 forks source link

[1.x] Allow setting title using a closure in functional API #79

Closed RVxLab closed 7 months ago

RVxLab commented 7 months ago

This PR adds the ability to set titles using closures when using the functional API.

As of 1.5.0 it's not possible to make "computed" titles using the functional API. To achieve this, the class-based API has to be used using the rendering lifecycle hook as described in the Volt documentation.

By allowing closures to be passed to the title function it will allow developers to defined titles like so:

state(['firstName' => 'Tom']);

title(fn () => 'This is the title');

// Or even

title(fn () => "Hi $this->firstName");

I will submit a separate PR for documentation.