Question

I have a blade template called 'main' and I wonder how I can render a sub template by calling a controllers method in my main template. Lets say I have a Controller WidgetsController with a method getSubView. The method returns a specific view with some data from (for instance) a database.

I already tried to @include a template but this will not call the controller which sets some necessary data to the view.

Thanks.

Was it helpful?

Solution 2

I don't entirely understand your question.

I think what you are looking for is a View Composer

It allows you to get data for a subview without having to create the data in every controller.

OTHER TIPS

views don't call services, they only take variables and put them on screen for presentation.

you're on the good side with @include(). you only need to gather the infos for that sub view beforehand in the controller, and pass it to the View::make('main')->with($vars).

you may also consider using another <?= View::make('subview')->with($vars->sub);?> within the the view. or just use the @extend functionality.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top