Reputation: 2960
I just started working with Laravel / Blade a few weeks ago and was wondering how Blade @include works.
I have a top level index view that then includes some other views. These other views require specific variables, which I know you can pass in through @include.
I also have a controller which creates the top level view. The controller is where I pass in the variables. And it seems that once they've been passed in to the top view, I don't need to pass them in to the sub views.
For a visual
controller
View::make('index', array('abc' => $abc))
index.blade.php
@include('sub.piece') - Do I still need to pass in the array with abc here?
sub/piece.blade.php
{{ abc }}
Does @include work like other includes where it's essentially a copy paste?
Upvotes: 0
Views: 279
Reputation: 219938
You do not have to pass in data that is already available to the parent view.
Passing data in @include
is useful for when the variable name differs for the two views.
Upvotes: 1