Erdss4
Erdss4

Reputation: 1125

How to pass a subview to a master view in Laravel?

I have a master view and depending on the URL and controller, it will load in another subview to a variable called $content, that's the idea.

Currently I am trying with:

return view("master")->with(["content" => view("pages.group")]);

So for example, if the URL is https://example.com/group/1 I am trying to get the subview included on my master template. Currently, it just gets escaped for XSS but I feel like this isn't the right way to do this?

Upvotes: 1

Views: 449

Answers (2)

Erdss4
Erdss4

Reputation: 1125

In the end after @lagbox mentioned it, using Laravel sections enabled me to use a master view and extend it when needed. https://laravel.com/docs/6.x/blade#extending-a-layout

Upvotes: 0

Sapnesh Naik
Sapnesh Naik

Reputation: 11636

I assume you are trying to display the sub-view content in the follwing way:

{{ $content }}

Change your syntax from {{ }} (Escaped output) to {!! !!} (Non escaped output).

{!! $content !!}

Upvotes: 1

Related Questions