Jakub
Jakub

Reputation: 1710

How to change layout for a full page render inline livewire component

I would like to use an inline livewire component for guest and app pages. By default, I understand that livewire reverts back to layout.app and I know you can update the default layout for all full page renders.

I am reading this docs https://laravel-livewire.com/docs/2.x/rendering-components and was able to get it working with regular approach of just having blade and .PHP file.

public function render()
    {
        return <<<'HTML'
            <div>
                example page view
            </div>
        HTML;
    }

Is it possible to do this thing from the docs in an inline component where we return the HTML directly?

public function render()
    {
        return view('livewire.show-posts')
            ->layout('layouts.guest');
    }

public function render()
    {
        return <<<'HTML'
            <div>
                example page view
            </div>
        HTML; ->layout('layouts.guest'); // something along the lines of this
    }

Upvotes: 1

Views: 2512

Answers (3)

user14967413
user14967413

Reputation: 1416

You can simply create a view which just renders given HTML and use it in classic render() function.

markup.blade.php:

{!! $markup !!}

Livewire component:

<?php

namespace App\Livewire;

use Livewire\Component;

class MyComponent extends Component
{
    
    public function getContent()
    {
        return <<<'HTML'
            <div>
                example page view
            </div>
        HTML;
    }
    
    public function render()
    {
        return view('markup', ['markup' => $this->getContent()])
            ->layout('layouts.guest');
    }
}

Upvotes: 0

Zukri Adinalta
Zukri Adinalta

Reputation: 11

maybe you can use it this way:

public function render()
    {
        $datas = [
            'data' => 'example page view'
        ];
        
        return view('livewire.show-posts', $data)
            ->layout('layouts.guest');
    }

Upvotes: 1

raimondsL
raimondsL

Reputation: 341

No it's not possible. You have to use view()->layout() arrow function

Upvotes: 3

Related Questions