I'll-Be-Back
I'll-Be-Back

Reputation: 10828

Storing @include() in a variable?

Is it possible to store the output of @include('view.name') into a variable?

Something like this:

$var = @include('view.name')
{{$var}}

The reason I want to do that I want to pass @include('view.name') into Blade::directive()

For example:

@blocksection([
        'Title',
        '<p>Descrption</p>,
         @include('view.name'),
])
// HTML 
@endblocksection

Upvotes: 0

Views: 98

Answers (1)

Abdelrhman Adel
Abdelrhman Adel

Reputation: 1187

I don't know if this is possible, but I'd rather do it in the following way (a cleaner approach I think):

  1. In the corresponding controller, render the view manually and store it in some variable $var = view('view.name')->render()
  2. Pass the variable to the target template return view('your template', ['var' => $var])
  3. Just use it now :D

Upvotes: 2

Related Questions