livewire / volt

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

Change layout for component-based Volt? #32

Closed iambateman closed 1 year ago

iambateman commented 1 year ago

Is it possible to change the layout when using a full-page class-based Volt component?

What I need

new class extends Component {

      protected string $layout = 'components.layouts.guest';

}

What I tried

I tried just including the function and following it with the class declaration, but it didn't work:

layout('components.layouts.guest');

new class extends Component { ... }

P.S. Volt is really cool, thanks for all your collective work on it!

nunomaduro commented 1 year ago

You need to use Livewire attributes:

new #[Layout('components.layouts.guest')]
class extends Component
{
    //
}; ?>
iambateman commented 1 year ago

That worked, thank you!

If someone else stumbles across this, the import for Layout is use Livewire\Attributes\Layout;