Ad

How To Pass A Subview To A Master View In Laravel?

- 1 answer

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?

Ad

Answer

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

Ad
source: stackoverflow.com
Ad